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 semi 2D type.
(A popular example being the original Zelda game.

To make it you need the following:

animations:
-top view facing forwards (1 frame animation)
-top view facing backwards (1 frame animation)
-top view facing right (we can make it face left with action-script) (1 frame animation)
-top view walking facing forwards (standard 2-3 frames)
-top view walking facing backwards (standard 2-3 frames)
-top view walking facing left (we can make it face right with action-script) (standard 2-3 frames)

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 move left/right/up/down

so, how do we set this up you ask?

First, lets put the animations in order and set up their action-script. In all of your "view facing" animations (use the facing right animation for facing left, so you have the same animations for left and right) (they should only be one frame), put the following script in the first frame:

for facing right:

stop();
if(Key.isDown(Key.RIGHT)){
this._x+=_global.walking_speed;
gotoAndPlay(2);
}

for facing left:


stop();
if(Key.isDown(Key.LEFT)){
this._x-=_global.walking_speed;
gotoAndPlay(2);
}

for facing forward (back of character to you):


stop();
if(Key.isDown(Key.UP)){
this._y-=_global.walking_speed;
gotoAndPlay(2);
}

for facing backwards (front of character facing you):


stop();
if(Key.isDown(Key.DOWN)){
this._y+=_global.walking_speed;
gotoAndPlay(2);
}

Now, you know those 2-3 frames of walking animation you have? places them after the first frame of their corresponding facing directions. For example, the walking right three frames of animation I have would be pasted into the three frames after the first frame of my view facing right frame. Making a total of 4 frames. (Again, make sure facing left and facing right / walking left and walking right animations are the same in everything except the script on the first frame).

At this point you should now really only have 4 animations (yes, two are the same [left and right]. Make a movie-clip called "character" and make 4 blank frames in it. label the frames "right", "left", "up", "down". Now put the 4 animations you have in their corresponding frames. (switching left and right doesn't matter). the animation with your character's back shown goes in "up". The animation where their front is shown goes in the "down".

now, put this script in the "character" movie-clip itself:


onClipEvent(enterFrame){
_global.walking_speed = 2; //you can change this number to change the walking speed.

if(Key.isDown(Key.RIGHT)){
this._xscale = 100;
gotoAndStop("right");
}//end Key down RIGHT

if(Key.isDown(Key.LEFT)){
this._xscale = -100;
gotoAndStop("left");
}//end key down LEFT

if(Key.isDown(Key.UP)){
gotoAndStop("up");
}//end Key down UP

if(Key.isDown(Key.DOWN)){
gotoAndStop("down");
}//end key down DOWN

}//end on Clip Event

and you're done!

Be Sociable, Share!