PDA

View Full Version : Animated Movement



flashnewb123
February 8th, 2008, 03:15 PM
I'm just started game making in Flash MX 2004, and I have a problem. I can get a movie clip to move around the screen, but when I try animating him walking in that direction it messes up. When I press a key, it will do the animation, but then go back to the original frame for that character. Like the character will be walking right, and when the animation finishes, it goes back to the first movie clip frame and then start the walking animation again. I am trying to get my character to move up, down, left, and right. Can anyone help me?

_marlon
February 8th, 2008, 06:37 PM
You don't want the animation to be him actually moving across the screen, you just want it to be an animation of him moving in that direction. Then in the code you want it so that when the user presses the right key (or whatever), the movie clips x value will go up (so it will move the movie clip to the right of the screen). And you set it up so that when they are moving, it will play the animation (to give the illusion that he is walking across the screen)

leonthelion
February 8th, 2008, 07:57 PM
_marlon you should probably give him some code =P
Anyway, if you want a top view movement you should have a frame of him in a walk animation. Make ONE frame where he starts walking (inside your main mc). Make the guy a movie clip (in the walking animation), and then animate inside that walking animation movieclip. Now on the main timeline (outside of all mcs) put this code ON the mc of the guy(I don't know what your animating). Put this code on him:

onClipEvent(EnterFrame){
if(Key.isDown(Key.RIGHT)){this._rotation=90}
if(Key.isDown(Key.RIGHT)){this.gotoAndStop(2)}
if(Key.isDown(Key.DOWN)){this._rotation=180}
if(Key.isDown(Key.DOWN)){this.gotoAndStop(2)}
if(Key.isDown(Key.LEFT)){this._rotation=270}
if(Key.isDown(Key.LEFT)){this.gotoAndStop(2)}
if(Key.isDown(Key.UP)){this._rotation=0}
if(Key.isDown(Key.UP)){this.gotoAndStop(2)}}
onClipEvent(keyUp){this._gotoAndStop(1)}

If it doesn't work or you need more help just say (I was writing that without testing D =
EDIT:
MAKE SURE THE ANIMATION IN THE MC IS WITH HIM STANDING STILL BUT STILL WALKING. =D

_marlon
February 9th, 2008, 08:33 AM
I was going to but I've never looked over AS2 so anything I give him would probably confuse him more.. But if he wants:



stage.addEventListener(KeyboardEvent.KEY_UP, keyIsUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyIsDown);

private function keyIsDown(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 37:
player_mc.x -= 2;
player_mc.gotoAndStop(2);
break;
case 39:
player_mc.x += 2;
player_mc.gotoAndStop(3);
}
}

private function keyIsUp(event:KeyboardEvent):void
{
player_mc.gotoAndStop(1);
}

(Just wrote it here so there may be a small mistake somewhere, but you get the picture)

If it's in AS3 chances are you'll need to change that code to make the movement a whole lot smoother, but that's the core bit of how it's done.

Here's a brilliant tutorial on detecting multiple key presses in AS3 (and making general keyboard input alot smoother:
http://www.8bitrocket.com/newsdisplay.aspx?newspage=6249


All the best
_marlon