I had some time today to fix up the input system of libgdx a little. As posted in an earlier post i wanted to have full mouse events in libgdx, that is, buttons and scroll wheel changes. I added that today. Here’s what changed:
[changed] InputProcessor.touchDown() and touchUp() are now also receiving the button that was pressed on the desktop, which is encoded as one of the Input.Buttons constants. On Android this will always be Buttons.LEFT
[changed] Added InputProcessor.touchMoved(). This will only be called on the desktop in case the mouse was moved over the window without any mouse button being down
[changed] Added InputProcessor.scrolled(). This will only be called on the desktop in case the mouse wheel was rotated. Reports 1 for a rotation towards you, -1 otherwise.
[changed] Modified InputAdapter and InputMultiplexer according to the changes in the InputProcessor interface.
[changed] Added Input.vibrate() and Input.supportsVibrator(). The former will take the duration to vibrate in milliseconds, the later tells you whether a vibrator is available.
[changed] Added Input.isButtonPressed(). Use this to determine wheter a specific button is pressed on the desktop. On Android the only valid button is Buttons.LEFT.
[changed] Added Input.justTouched(). This will return true if the screen was touched/mouse button was pressed between the current and the last frame. Also works for multi-touch/multiple mouse button presses. It’s a short cut if all you want to know is whether there was a new touch down event. Use the InputProcessor interface for more info, e.g. pointer or button.
This will not influence your current code in any harmful way. The only thing you need to fix is to add the new parameter int button to the methods InputProcessor.touchUp() and InputProcessor.touchDown() as well as stubs for InputProcessor.touchMoved() and InputProcessor.scrolled(). That’s it, Eclipse should help you to fix this in no time.
Also check out the new features, namely vibrator access on Android as well as the Input.justTouched() method which grants you a quick way to check whether a touch down event occured between the current and last frame. In some situations that might be easier to use than implementing and registering an InputProcessor/InputAdapter.
I tested this heavily on 2 machines (windows/lunix) and 4 Android devices without any sign of a problem. In case you find one please report it!
The nightlies and SVN trunk are up to date, the only thing i need to fix up is the awesomium backend as well as the gdx-helloworld and gdx-invaders projects. I’ll do that tomorrow, they are not critical to any of your code.
In other news: i bought myself a nice HTC Desire HD. Love it. That’s the 5th Android device in one year. I think i have a problem 🙁