Game Development Reference
In-Depth Information
The CIwAnimPlayer class allows us to detect when a one shot animation has
completed, by calling the IsCurrentAnimComplete method that will return true
when the animation has finished.
There is also the IsCurrentBlendComplete method that will return true when the
animation player has finished blending between two animations.
Detecting when an animation has looped is also possible, although CIwAnimPlayer
does not provide us with a quick shortcut way of detecting this event. Instead, we
have to do a little manual flag testing.
At any time, the animation player can be updating two main animations: current
animation (defined as the animation that was last specified using the PlayAnim
method) and the previous animation (the one that was playing at the time PlayAnim
was last called with a blending interval).
The current status of these two animations are stored in instances of the
CIwAnimBlendSource class, which we can access using the CIwAnimPlayer class'
methods named GetSourceCurr and GetSourcePrev . The CIwAnimBlendSource
class has a method called GetFlags that returns playback status information as
a bitmask. To detect if the animation has looped, we just need to see if the flag
CIwAnimBlendSource::LOOPED_F is set. The following source code shows this in
action:
if (lpAnimPlayer->GetSourceCurr()->GetFlags() &
CIwAnimBlendSource::LOOPED_F)
{
// Animation has looped!
}
If you prefer this approach, you can also use the flag
CIwAnimBlendSource::COMPLETE_F to detect when a single shot animation
has finished.
Optimizing animation playback
Do you remember that we calculated the current animation frame by calling the
Update method of CIwAnimPlayer ? This method has to do quite a lot of work,
some of which we might not actually need to do on a frame-by-frame basis. For
example, if an in-game character is currently not visible on the screen, we might
want to ensure that we still step through its animation; but calculating the bone
positions for the current frame of animation is a waste of processor time as we
won't be rendering the animation.
 
Search WWH ::




Custom Search