Input.isKeyJustPressed() method?
See original GitHub issueI would find a isKeyJustPressed(int)
method similar to the justTouched()
method very helpful.
I know this kind of event can be captured using InputProcessor
, but this method would come in handy if
- you can’t easily use
InputProcessor
, for example if you have several game objects that want to listen for input. In that case you need to write another class which manages an InputMultiplexer and make it available to all objects that want to listen to input. - you just want to check one button. Implementing InputProcessor or creating an annonymous subclass of InputAdapter seems like a lot of boiler plate code for one button.
- you need things to happen at a specific point / in a specific order in your
render()
method. This requires you to create flags for all your buttons and then check them in the desired order in the render method.
I can make a PR if you want…
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
com.badlogic.gdx.Input.isKeyJustPressed java code examples
Returns whether the key has just been pressed. Popular methods of Input. setInputProcessor. Sets the InputProcessor that will receive all touch and key...
Read more >libGDX: Why doesn't Gdx.input.isKeyJustPressed() work?
I'm going to use the isKeyPressed() method and prevent multiple calls by saving the last key state and make only a call when...
Read more >Libgdx isKeyJustPressed(Input.Keys.UP) does not work and ...
From using a similar function isKeyPressed() , when I type in (for example) UP I have to press the right arrow key to...
Read more >Search - appsloveworld
isKeyPressed/Gdx.input.isKeyJustPressed-android-Java. ... If I might suggest an alternative approach, it sounds like what you really want is to apply a ...
Read more >Input - TUKE
... done by calling static methods isKeyPressed(Key) or isKeyJustPressed(Key) . Keyboard keys are translated to the constants in Input. ... public Input() ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my code I currently use this pattern in several places because I encountered one or more of the problems listed above.
I thought maybe more people have these problems and this method would simplify their game code.
I don’t think this requires a new method. Just create a boolean[] of length 256. At the begin of every frame reset all its value to false. Then on each keydown you set the index that equals the keycode to true. Through the rest of your loop you can check this value to see if the key was pressed this frame.