Time for action – playing an animated model

Everything is set up, but if you run the application now, the model is stuck in its idle pose. Use what you learned in the previous chapter about the AnalogListener and ActionListener, and configure the Space bar to make the character walk toward you gradually, while playing the walk animation!

  1. Write an ActionListener that waits for the MAPPING_WALK trigger, and then tests whether the key is pressed or up. If the key is pressed, test if ANI_WALK is still playing on the animation channel; if it isn't, play ANI_WALK again. If the key is not pressed, play ANI_IDLE again.
    private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean isPressed, float tpf) { if (name.equals(MAPPING_WALK) ...

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.