Time for action – responding to animation events

What if you want to play the sound loop of footsteps while walking, or reset the model to a neutral pose after crouching, or before jumping? To detect the start and end of animation events, your SimpleApplication must implement the com.jme3.animation.AnimEventListener interface.

public class AnimateModel extends SimpleApplication
        implements AnimEventListener {…}
  1. Register the AnimEventListener (this) to each AnimControl instance:
    control.addListener(this);
  2. Now you can implement the onAnimChange() method. It is called every time a new animation starts.
    public void onAnimChange(AnimControl control, AnimChannel channel, String animName) { if (animName.equals(ANI_WALK)) { System.out.println(control.getSpatial().getName() ...

Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.