Game Development Reference
In-Depth Information
Not much to see here really—we have just initialized all our data. Note that the Sprite
reference needs to be set in the initialization list otherwise, the code will not compile. This
is how references work in C++—they need to be initialized as soon as possible. Another
thing to take note of is the nullptr initialization of the current animation. It is always a
good practice to initialize pointers to nullptr .
Animator::CreateAnimation() is a bit more interesting—let's take a look:
Animator::CreateAnimation() creates an animation using a number of paramet-
ers. As we established earlier, each animation needs a name so that we can reference it
from outside the class. Also, each animation has a texture and duration associated with it.
The loop parameter determines whether the animation should loop or play only once.
With all these parameters, we will initialize a new instance of the animation and place it in
the m_Animations list.
If that was our first animation, we would want to set that animation as the current one.
This ensures that we have something to play once the Animator::Update() method
is called. Animator::SwitchAnimation(Animation*) does exactly that—it
takes an animation and sets it as the current animation. We'll see how that works in a mo-
ment.
The last line of the method returns a reference to the animation that we just created. This
enables the caller to further manipulate the animation by adding frames or changing some
of its initial values.
Search WWH ::




Custom Search