Game Development Reference
In-Depth Information
How it works…
The
AnimControl
class is responsible for playing and keeping track of the animations.
AnimChannel
has a list of
Bones
that the animation should affect.
Since we let the enum decide the animation parameters for us, we don't need much code in
the
setAnimation
method. We do however need to make sure we don't set the same an-
imation if it is already playing or it could get stuck, repeating the first frame in a loop.
The
onAnimCycleDone
method is called from
AnimControl
whenever an animation
reaches the end. Here, we decide what will happen when this occurs. If the animation is not
looping, we must tell it what to do next. Playing the idle animation is a good choice.
We also have one special case. If you look at the animation list, you will notice that Jaime's
jump animation is split into three parts. This is to make it easier to handle jumps of differ-
ent lengths or the falling animation.
We will tell
AnimControl
to change the animation to a jumping action once
JumpStart
is done. We never change to
JumpEnd
once the jumping action has taken
place however. Instead, this should be called from elsewhere when Jaime hits the ground
after he jumps. How this is measured is dependent on the game logic, but since we're using
the
Control
pattern, we could use
controlUpdate
to check Jaime's whereabouts.