Game Development Reference
In-Depth Information
vious section, we find the current frame by multiplying the scaled time by the number of
total animation frames and round that number down.
The next part is new. If we want the animation to keep looping, we use the modulo operat-
or ( % ) to bring the frames around. Otherwise, we play the animation only once and use the
last frame until the animation is changed (or replayed).
Now that we have the current frame, we only need to set the texture rectangle for the
sprite. Since we hold all the frames inside the animation, retrieving them is extremely
easy—use the Animation::m_Frames vector as an array by calling its index operator
with the currentFrame index.
That's it—a powerful sprite animator is created without much effort at all. Next, we will
look at some examples of how we can use it in practice.
Search WWH ::




Custom Search