Coding the player animations
In this section, we will get to use the Animator
class we have just coded. We will obviously be using the getCurrentFrame
function but additionally, we will be referring to the individual frames in the texture atlas like the player boosting, shown again next.
Figure 18.4: Player boosting
Furthermore, we have seen that our Animator
class can reverse the order the frames are animated, but we also need to flip the textures horizontally whenever the player is facing to the left. In this code, we will see how to detect that they need to be flipped as well as flipping them. For example, the preceding image will sometimes need to be drawn like this:
Figure 18.5: Player boosting flipped
Achieving this is very quick and easy and we will see it in action for all player images soon. The PlayerGraphics.h
file has everything we need in it; just uncomment the following code:
// We will come back to this soon
class Animator;
And the following...