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;
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".