Table of Contents | ||||||||||||||||
|
||||||||||||||||
AddAnimation | ||||||||||||||||
Purpose Add a new animation to an existing sprite object |
||||||||||||||||
Protoype void CSpriteMngr::AddAnimation (string str_anim_id, animation v_anim, int i_anim_delay, int i_frame_delay, bool b_repeat, bool b_play = false, int i_direction = FORWARD, int i_def_frame = NO_DEF_FRAME) |
||||||||||||||||
Parameters
|
||||||||||||||||
Description The Basics In order to add an animation you must first have at least one sprite object to assign that animation to. The sprite object that is to receive the animation must be locked with LockSprite(). Each animation assigned to a sprite object must have a unique identifier for later reference. Note that you can add the same animation ID to multiple sprite objects. Each animation will have a sequence of values that correspond to the various cells in the sprite's image template. This animation sequence is an STL vector class. Time Delays An animation can have two seperate delays. The frame delay causes the animation sequence to pause after a frame has been rendered and waits the amount of milliseconds specified with i_frame_delay before rendering the next frame. Then there is also the animation delay, specified with i_anim_delay. This delay starts at the end of the animation, after the last frame delay. If the animation is looping, then the sequence does not begin again until the animation delay timer is expired. Time delays can be changed with SetAnimDelay() and SetFrameDelay().
Looping, Playing and Direction When you want an animation to automatically repeat itself when it reaches the end of its sequence then you should set the b_repeat flag to TRUE. You can change the looping anytime with SetRepeat(). If you want to immediatly play the animation, then pass in TRUE for b_play. This will automatically load and begin playing the animation. You can also set the direction that the animation will play in, beginning to end (FORWARD) or end to beginning (REVERSE). This direction can be changed anytime with SetDirection(). Default Frame The default frame is a frame number in the animation sequence that the animation reverts to when it is stopped. This is not a frame value, so an in an animation sequence of: 1, 3, 6, 8, 3, 1, the valid values for i_def_frame would be 0-5, with 0 being the first frame in the sequence (value of 1). If no default frame is specified (NO_DEF_FRAME) then when an animation is stopped the sprite freezes at the current frame. |
||||||||||||||||
Use CSpriteMngr sprite; // build animation animation my_anim; my_anim.reserve(5); for (int x=0; x<5; ++x) my_anim[x] = x; // sprite is locked sprite.AddAnimation("my_anim", my_anim, 0, 2000, true, FORWARD, 0); |
||||||||||||||||
|
||||||||||||||||
|