This is how I do my frame controller basically in logical means.
- Features:
- dependent on code, not on the swf’s framing
- very flexible and expandable
- reusable for any other animation that require distinct control
- can cheat key framing
- really simple
Structure:
Basically the primary movieclip of the character shall contain a few designated frames for each possible animation it shall have. For this case I have frame 1, 3, 5 and 7 each allocated as stand/idle, running, jump and double jump animations respectively and all have “mc” as their instance names. This is also shown on these images:
Then each animation respectively has the animation sequence tween. And take note: that each animation is not key framed with one’s or two’s yet they set on a five’s key framing. This is because our frame controller must be able to tolerate slight FPS reductions based on time (detailed on this post). So when the animation is played from the timeline during design time it would appear to be quite slower than expected.
Also take note of each of the animation’s total frames; they’ll be used when playing through them. After setting up the structures here is where the controller comes in.
Code:
This is assumed to be within your character’s class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | var _cframe:Number; var _ccframe:Number; var mc:MovieClip; // animation movieclip child function update(){ controlFrame(); // some more codes here gotoAndStop( _cframe ); mc.gotoAndStop( _ccframe ); } function controlFrame() { var frameSkip:Number = int( 4 * Engine.frameSpd ) + 1; switch( _cframe ) { case 1: // stand/idle if ( _ccframe + frameSkip > 100 ) _ccframe = ( _ccframe + frameSkip ) % 100 else _ccframe += frameSkip; break; case 3: // run if ( _ccframe + frameSkip > 80 ) _ccframe = ( _ccframe + frameSkip ) % 80 else _ccframe += frameSkip; break; case 5: // jump if ( _ccframe + frameSkip > 65 ) _ccframe = ( _ccframe + frameSkip ) % 65 + 25; else _ccframe += frameSkip; break; case 7: // double jump if ( _ccframe + frameSkip > 50 ) { _ccframe = ( _ccframe + frameSkip ) % 50 + 25; _cframe = 5; } else _ccframe += frameSkip; break; default: break; } } |
_cframe is the current animation frame of the character and _ccframe acts like a play head for the mc animation itself.
Line 11: You can see why we used five’s key framing because our frameSkip is 5 by default and is then altered by the frameSpd. So if frameSpd is not used, then the controller will basically be frame based.
Line 15 & 19: Check if the sum of frameSkip & _ccframe is greater than the total frames then use modulus (%) to reset.
Line 16, 20, 24 & 30: Else just add the frameSkip to _ccframe
Line 23 & 28: Check if the sum of frameSkip & _ccframe is greater than the total frames then use modulus (%) to reset and add a special offset specific with respect to the animation intended.
Line 29: Transfers the animation then from double jump to jump with the same _ccframe
Line 7 & 8: The update will them take care of updating the right movieclips based on what _cframe & _ccframe was changed into.
A sample which uses this frame controller. Arrows keys to move.













•