Game Development Reference
In-Depth Information
mainChannel = animControl.createChannel();
animControl.addListener(this);
}
4. We define a new method called
setAnimation
in the following code. Inside
this, we set the supplied animation to be
mainChannel
as the current one if it's
not the same as the one playing now. We also set
loopMode
according to how
it's defined in the enum:
public void setAnimation(Animation animation) {
if(mainChannel.getAnimationName() == null ||
!mainChannel.getAnimationName().equals(animation.name())){
mainChannel.setAnim(animation.name(),
animation.blendTime);
mainChannel.setLoopMode(animation.loopMode);
}
}
5. In the
onAnimCycleDone
method, we create a control so that all animations
that don't loop return to the idle animation, with the exception of
JumpStart
,
which should switch to
Jumping
(as in midair) as shown in the following code:
public void onAnimCycleDone(AnimControl control,
AnimChannel channel, String animName) {
if(channel.getLoopMode() == LoopMode.DontLoop){
Animation newAnim = Animation.Idle;
Animation anim = Animation.valueOf(animName);
switch(anim){
case JumpStart:
newAnim = Animation.Jumping;
break;
}
setAnimation(newAnim);
}
}
6. That's all that's needed to create a class that manages animations! To set this up
from an application, we just need to load a model in the application and add the
following line: