Game Development Reference
In-Depth Information
How to do it...
You can handle jumping animations by performing the following steps:
1. For this, we'll need to add two more Booleans to our animation control:
jumpStarted and inAir .
2. We trigger the first part of the animation in the onAction method, as shown in
the following code. The jumpStarted Boolean is used to let the class know that
other animations should not start while the character is the jumping state:
public void onAction(String binding, boolean value,
float tpf) {
if (binding.equals("Jump") && value) {
jumpStarted = true;
setAnimation(Animation.JumpStart);
}
}
3. The onAnimCycleDone method should switch animations back to the jumping
action once JumpStart has finished playing. We also set inAir to true , 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;
inAir = true;
break;
}
setAnimation(newAnim, channel);
}
}
4. The controlUpdate method is suitable to check whether the character has
landed after jumping (or falling). We check this directly in BetterCharacter-
Search WWH ::




Custom Search