Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling jump animations


In this recipe, we'll show how the jumping animation can be handled in the animation manager control from previous recipes. Why does this require its own recipe? Animation-wise, jumping is usually a set of sequenced animations. If we look at Jaime, for example, there's JumpStart, Jumping, and JumpEnd. Normally, sequenced animations can be handled in the onAnimCycleDone method; when one animation ends, it can trigger the next. Jumping is different though since the middle jumping animation is indefinite and is on a loop. How long it plays depends on how long the character is in the air, which is driven by the gameplay or its physics.

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...