- Flash Tutorial 1
- Flash Tutorial 2
- Flash Tutorial 3: Event Detection
- Flash Tutorial 4: Fun with the Cursor!
- Flash Tutorial 5: A Moving Character Type 1
- Flash Tutorial 6: A Moving Character Type 2
- Flash Tutorial 7: AI Enemies Type 1
- Flash Tutorial 8: AI Enemies Type 2
- Flash Animation/Effects Tutorial 1: Motion Tweens
- Flash Animation/Effects Tutorial 2: Shape Tweens
Flash Tutorial 5: A Moving Character Type 1
This is for action-script 2.0
There are two types of moving character. As I like to classify them, full 2D and semi 2D. This tutorial is for the full 2D type.
(A popular example being the original Mario game.
To make it you need the following:
animations:
-right view standing (1 frame)
-right view walking (standard of 3-4 frames)
-right view jumping (standard of 12 frames (tween up and down))
-right view crouching (1 frame)
(there are no left view because action-script can change it's direction dynamically).
Detection Scripts:
-Detect the pressing of the UP key
-Detect the pressing of the Down key
-Detect the pressing of the Left key
-Detect the pressing of the Right key
Action Scripts:
-Flip the character
-Make the character jump
-Make the character move left/right
so, how do we set this up you ask?
First, make a movie clip for each of the animations (all 4).
Then, Make a new movie clip called "character" and give it the instance name "character". Make 4 blank frames in the "character" movie-clip and put one of the animation movie-clips in each of them. Then put the Stop(); command on all of the 4 frames. Now, label each frame as appropriate to its animation "walking" "standing" "jumping" "crouching".
now It's time for the action-script! (To be placed in the "character" movie-clip).
Code:
onClipEvent(enterFrame){
if(Key.isDown(Key.RIGHT)){
this._xscale = 100;
this._x += 2;
if(_global.jumping != "yes"){
gotoAndStop("walking");
}
}//end Key down RIGHT
if(Key.isDown(Key.LEFT)){
this._xscale = -100;
this._x -= 2;
if(_global.jumping != "yes"){
gotoAndStop("walking");
}
}//end key down LEFT
if(Key.isDown(Key.UP)){
gotoAndStop("jumping");
}//end Key down UP
if(Key.isDown(Key.DOWN)){
gotoAndStop("crouching");
}//end key down DOWN
}//end on Clip Event
Now for the last bit of scripting.
Make sure you put the stop command in the last frame of every animation except "walking";
Now put:
Code:
_global.jumping = "yes";
at the first frame of your jumping animation.
and:
Code:
_global.jumping = "no"
at the end of your jumping animation.
and your done!
Printer-friendly version- Login or register to post comments
- Send to friend
- PDF version