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).


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:

[ccN_actionscript]
_global.jumping = "yes";
[/ccN_actionscript]
at the first frame of your jumping animation.

and:
Code:

[ccN_actionscript]_global.jumping = "no"[/ccN_actionscript]

at the end of your jumping animation.

and you're done!

Be Sociable, Share!