javalibgdx

Java - LibGDX - What is the difference between isKeyPressed and isKeyJustPressed?


What is the difference between isKeyPressed and isKeyJustPressed?!

I searched the docs. for the difference and just found:

isKeyPressed: Returns whether the key is pressed.

isKeyJustPressed: Returns whether the key has just been pressed.

Anybody knows something that explains better?!


Solution

  • isKeyPressed detects whether the key is pressed, keyDown and/or still pressed.

    isKeyJustPressed detects the keyDown event (the last frame), triggering the event only once. Holding down the key does not trigger the event twice, you need to execute keyUp and then trigger it again.