Game Development Reference
In-Depth Information
Using the animator
Let's start with the example of the rotating crystal. Here is the initialization part:
It is important to note that a sprite has to exist already in order to create an animator be-
cause it takes a sprite reference in its constructor. Once we create an animator for the sprite,
we will add an animation. Since we are replicating our previous example, there is only one
animation. The animation's name is Idle and it uses the spriteSheet.png texture. It
takes one second to complete and it is set to a looping state.
Once we get the animation reference, we will add some frames from the texture. We know
how big the sprite is so, in order to get all the frames from the texture, we start from (0, 0)
and continue horizontally eight times by moving with 32 pixels each time. This is all done
inside the Animation::AddFrames() method.
That's pretty much it. The only thing left to do is to call the update method of Animator
in the update frame of the game loop:
Search WWH ::




Custom Search