For some reason unknown to me, when I use Buttons.LEFT with an event handler, nothing happens. Here is my code:
if (Gdx.input.isKeyPressed(Buttons.LEFT)) {
System.out.println("Mouse clicked!");
}
If I do, say, Keys.LEFT, or justTouched(), the message prints, but not when I do Buttons.LEFT. And yes, I'm 100% I'm pressing my mouse button, and that it works correctly. ;)
Thank you!
1 Answer 1
This is because Gdx.input.isKeyPressed() is for Keyboard input. If you want mouse button input you should be doing
if (Gdx.input.isButtonPressed(Buttons.LEFT)){
System.out.println("Mouse clicked!");
}
Buttons and Keys are different classes, and as such have matching methods in input. Explore the Input API Javadocs of theirs a bit more, it's helped me quite a lot.
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Input.html