Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-24-2004, 05:28 PM   #1
special nobody
unregistered user
special nobody's Avatar
Join Date: Dec 2004
Location: cali
Posts: 13
Default running animation

ok, have a standing animation movie clip on frame 1 of a movie clip, then on frame 18 (dont ask) i have the movie clip of running. i want it so when you run to the right, right button, you see the animation of running but when you release, you go back to the standing animation. two problems. one is that the running animation keeps restarting as i hold it down. second, scence there is no "if(Key.isUp(" function it keeps repeating the MC of running.

here is my code so far...

if(Key.isDown(Key.RIGHT)) {

special nobody is offline   Reply With Quote
Old 12-24-2004, 07:24 PM   #2
mmm..pi..3.14..'s Avatar
Join Date: May 2004
Location: Denver, CO
Posts: 2,740

well, I would recommend using a Key listener instead of just testing for KeyDown in your MC's actions. Put this code into the frame actions:

PHP Code:
var myListener:Object = new Object();
myListener.onKeyDown = function() {
    if (
Key.isDown(Key.RIGHT)) {
trace("Move Right");
That will make it so he will only move when you press the key down, when you release the key he stops moving

The reason you keep seeing the running animation starting over is because you have it keep going to frame 18. What I would recommend doing is making a tween with the amount of frames needed for the animation to make a complete "cycle". Then on the last frame of that tween in the actions put a "gotoAndPlay()" action that goes back to the beginning of the tween, that way it will look like the running is constant, even though the tween may be only 12 frames long

In the code I gave you you could just tweak it so that when the key is down, the tween plays, and when it's not, tell it to jump to a certain frame which has your guy standing still

Eric Hainer
Unleaded Software
Email: Eric followed by the AT symbol, unleaded software (one word) DOT com
Denver Web Design
mmm..pi..3.14.. is offline   Reply With Quote
Old 12-25-2004, 02:30 AM   #3
maker of abstract sh*t
high1memo's Avatar
Join Date: Jul 2003
Posts: 58

for best results, you shouldnt use the KEYPRESSES to control what ANIMATION to play. You should use the KEYPRESSES to just set what the guy WANTS TO DO, and use THAT combined with what he is currently doing to set what animation to play. Goin back to the dear old prince of persia (original oldskool 2D version) days , you also want to make sure that when you let go of the RIGHT button, he doesnt just snap to the standing animation, but first finishes his RunLoop Loopable animation, then plays the Run2Still transitional animation, and then starts the StillLoop Loopable animation.

//e.g. lets say you have a long animation organized as follows:
0-10 StillLoop // Loopable standing idle animation
11-15 Still2Run // starting to Run transition animation, which goes form standing Still to Running
16-30 RunLoop // Loopable Run animation
31-35 Run2Still // stop Running transition animation, which goes from Running to standing.

//I will create these variables to make the code more readable:
StillLoop_Start = 0;
StillLoop_End = 10;
Still2Run_Start = 11;
Still2Run_End = 15;
RunLoop_Start = 16;
RunLoop_End = 30;
Run2Still_Start = 31;
Run2Still_End = 35;

//then your logic should be:

on(right.pressed) bRunning = true;
on(right.released) bRunning = false;

Do_Every_Frame {
switch(currentframe) {
case StillLoop_End: if(!bRunning) gotoAndPlay(StillLoop_Start); break;
case Still2Run_End: if(!bRunning) gotoAndPlay(Run2Still_Start); break;
case RunLoop_End: if(bRunning) gotoAndPlay(RunLoop_Start); break;
case Run2Still_End: if(bRunning) gotoAndPlay((Still2Run_Start); else gotoAndPlay(StillLoop_Start); break;

I thinks its pretty readable. Basically everytime you reach the end of a chunk of animation, you ask "now where shall we go from here?".

If the chunk of animation is quite long, and you dont nessecarily want to wait till the end of the whole chunk before switching, you can add those frames in the switch as well. e.g. in the old prince of persia the run cycle was two full steps, but if you let go of the right button before he even completed the first step, he would switch midway through the loop after just completing the first step. so just add a new CASE to the SWITCH:
case (RunLoop_Start + RunLoop_End)/2: if(!bRunning) gotoAndPlay(Run2Still_Start ); break;

i.e. we are saying "if, when you are halfway thru the run loop, you should not be running anymore, then stop running".
high1memo is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT. The time now is 03:20 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.