Libgdx Input, InputProcessor, InputAdapter and InputMultiplexer changes!

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 🙁

7 thoughts on “Libgdx Input, InputProcessor, InputAdapter and InputMultiplexer changes!

  1. Great changes as always, congrats on the desire HD! Hope you like it, you might want to put setCPU to auto-under clock in there, I’ve heard battery life isn’t the greatest!

  2. Nice! I’m considering libgdx as my platform for desktop games too, so I’m happy with these changes. If your’e going in that direction, I’d suggest options (for desktop ofcoz) for hiding/changing mouse cursor.
    What Androdevices do you have now?

  3. Hi,

    I’m looking forward to using these changes, but too lazy to attempt building libgdx.
    When do you plan to release the next version ?


  4. Actually I overcame the laziness and managed to build libgdx.
    But that was a bit painful, so I will remember the nightly build next time.

    Thanks a lot !

Leave a Reply

Your email address will not be published.