onAction and onAnalog

1E`1{X7~SJB4TT}$6~VG9Y
OnAnalog fires a little later than onAction when I bounce the W button
I want the onAction to always fire after onAnalog when the button pops up

I need some guidance and advice :thinking:

onAnalog for button presses is nearly useless.

Almost always it’s better to track pressed and unpressed.

But what you are asking is essentially impossible because when JME gets the button up event then I think it will always send at least one more onAnalog().

1 Like

Rereading this document gives me the answer
wiki

  private final ActionListener actionListener = new ActionListener() {
        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("Pause") && !keyPressed) {
                isRunning = !isRunning;
            }
        }
    };

    private final AnalogListener analogListener = new AnalogListener() {
        @Override
        public void onAnalog(String name, float value, float tpf) {
            if (isRunning) {
                if (name.equals("Rotate")) {
                    player.rotate(0, value * speed, 0);
                }
                if (name.equals("Right")) {
                    Vector3f v = player.getLocalTranslation();
                    player.setLocalTranslation(v.x + value * speed, v.y, v.z);
                }
                if (name.equals("Left")) {
                    Vector3f v = player.getLocalTranslation();
                    player.setLocalTranslation(v.x - value * speed, v.y, v.z);
                }
            } else {
                System.out.println("Press P to unpause.");
            }
        }
    };

I didn’t even understand… until I had seen it many times
(Thank you for your reply)