Game Development Reference
In-Depth Information
As promised, here is one of the overloads of the
Animator::SwitchAnimation()
method:
Since we are potentially switching to a new animation, we need to change the texture of
the sprite to the texture of the new animation. However, since both
animation
and
m_CurrentAnimation
can be
nullptr
, we have to check for that first. If
anima-
tion
is not
nullptr
, we can safely use the texture name to call our
AssetManager
and ask for the texture's reference. In this case, even if the texture of the previous anima-
tion is the same as this one, the overhead of triggering a change will be minimal because
we are only dealing with references.
Next, we set the
m_CurrentAnimation
pointer to
animation
for later use and reset
the time. The
animation
parameter, being
nullptr
, is fine in this instance since it
just means that we do not want an animation to be playing at this time.
There is an overload of the
Animator::SwitchAnimation(Animation*)
func-
tion, which takes
string
instead of
Animation*
. This function is public and is used
to change animations based on their name, rather than direct pointers. Here is its imple-
mentation: