Game Development Reference
In-Depth Information
Playing back a 3D animation
In order to play back an animation, we need to let Marmalade know which
animation we want to play, how fast it should be played back, and whether we
want it to be a one shot or looping animation. All this and more is provided by
the
CIwAnimPlayer
class.
After creating a new instance of
CIwAnimPlayer
, we must provide it with a pointer
to the skeleton instance for animation. This is done as follows:
CIwAnimPlayer* lpAnimPlayer = new CIwAnimPlayer;
lpAnimPlayer->SetSkel(lpSkel);
The player object is now ready to start animating, so we just need to pass it details
about the animation we want to play. This can be done with just a single line of code:
lpAnimPlayer->PlayAnim(lpFlagWobble, 1.0f,
CIwAnimBlendSource::LOOPING_F, 0.0f);
The
PlayAnim
method first takes a pointer to the
CIwAnim
instance we wish to play.
It then expects to see a playback speed, some control flags, and a blending interval.
The playback speed is specified so that a value of
1
yields the normal exported
animation speed. Doubling this value will play the animation back at twice the
speed, and so on.
The function's third parameter is a set of control flags that are primarily used to
indicate whether the animation should loop when it reaches the last key frame. If
looping is desired, the flag
CIwAnimBlendSource::LOOPING_F
should be used.
There are a number of other values defined by
CIwAnimBlendSource
, but most of
these are intended for read-only status flags and the
CIwAnimPlayer
class provides
other methods that should be used to determine the current status. Therefore, the
only other flag that will be used in this method is
CIwAnimBlendSource::RESET_IF_
SAME_F
, which will force the animation player to restart the specified animation if it is
already the current animation. If an animation that is already being played is passed in
to the
PlayAnim
method, the request will be ignored unless this flag is used.
The animation player is now initialized, so the final thing that must be done is
instruct it to calculate the required animation frame. This is done by calling the
Update
method of the
CIwAnimPlayer
instance on every iteration of the main
game loop, as shown in the following code:
lpAnimPlayer->Update(lTimeStep);
Search WWH ::
Custom Search