See http://code.google.com/p/libgdx/wiki/InputEvent - you need to handle input events instead of polling, extending the InputProcessor and passing your custom input processor to Gdx.input.setInputProcessor ().
EDIT:
public class MyInputProcessor implements InputProcessor { @Override public boolean touchDown (int x, int y, int pointer, int button) { if (button == Input.Buttons.LEFT) {
And wherever you want to use this:
MyInputProcessor inputProcessor = new MyInputProcessor(); Gdx.input.setInputProcessor(inputProcessor);
If you find it easier to use this template:
class AwesomeGameClass { public void init() { Gdx.input.setInputProcessor(new InputProcessor() { @Override public boolean TouchDown(int x, int y, int pointer, int button) { if (button == Input.Buttons.LEFT) { onMouseDown(); return true; } return false } ... the other implementations for InputProcessor go here, if you're using Eclipse or Intellij they'll add them in automatically ... }); } private void onMouseDown() { } }
source share