Game Development Reference
In-Depth Information
Ignore
Animator::FindAnimation()
and
Animator::SwitchAnimation()
for now, we will come back to the them later. What we are interested in right now is the
data. As you can see, there isn't a sprite instance in
Animator
, but only a reference. This
means that the sprite has to be constructed outside the class, and then should be passed to
the constructor of
Animator
.
Other than the
Sprite
reference, there is the time accumulation counter (the same one
which we used in the previous section of this chapter), a list of animations, and a pointer
to the currently running animation. Note how we don't have a
vector
to store anima-
tions, but a list. This is mostly specific to C++, but you cannot keep pointers and referen-
ces to the elements in a
vector
—they will become invalid once we start adding or re-
moving elements from it. The
list
class, on the other hand, doesn't have such a prob-
lem, because its implementation ensures that pointers and references remain valid even
after adding/removing elements from it.
Now, let's inspect the functionality that the
Animator
class provides by looking at its
public member functions: