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 {…}
Register the
AnimEventListener (this)
to eachAnimControl
instance:control.addListener(this);
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() + " started walking."); } else if (animName.equals(ANI_IDLE)) { System.out.println(control.getSpatial().getName() + " started being idle."); } }
You can also implement the
onAnimCycleDone()
method of the interface...