Handling multiple keypresses each update, like UP + LEFT

Hello.

I wanted to know how can I handle multiple keypresses when I need to handle key combination each update? For example when player holds UP and LEFT.

Problem is when I use events I get UP and LEFT separately and I couldn’t figure out how to combine logic for it to work.



I’ve managed to handle it through LWJGL directly, but still would like to learn how to do it JME3 style and I’m wandering if I missed something:



[java] public void update(float tpf)

{

Spatial player = Game.get().getPlayer();

boolean isMoving = false;

ControlMovable moveable = player.getControl(ControlMovable.class);



Vector3f newDirection = new Vector3f();

if (Keyboard.isKeyDown(Keyboard.KEY_W))

{

newDirection.addLocal(0, 1, 0);

isMoving = true;

}

if (Keyboard.isKeyDown(Keyboard.KEY_A))

{

newDirection.addLocal(-1, 0, 0);

isMoving = true;

}

// …

if (isMoving)

{

newDirection.normalizeLocal();

moveable.getDirection().set(newDirection);

moveable.setMoveSpeed(moveable.getMaxMoveSpeed());

}

else

{

moveable.setMoveSpeed(0);

}

}[/java]



I’ve seen ComboMoves but it seems it’s not meant to handle this type of input. Any suggestions?

When you get the pressed event for UP set a moveUp flag to true. When you get release event for UP set the moveUp flag to false. Do your logic based on this flag.



…or just use a KeyTrigger.

good old flags, thanks!

Check combo moves

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:combo_moves

@Kova said:
I've seen ComboMoves but it seems it's not meant to handle this type of input. Any suggestions?


@wezrule said:
Check combo moves
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:combo_moves


It's like deja vu all over again.

ups :stuck_out_tongue: