Game Development Reference
In-Depth Information
Music streaming
To stream music for playback, call Gdx.audio.newMusic() . The supported file
formats are WAV, MP3, and OGG. However, the iOS version currently supports
the WAV and MP3 formats only.
The input module
The input module can be accessed either through Gdx.getInput() or using the
shortcut variable Gdx.input .
In order to receive and handle the input properly, you should always implement the
InputProcessor interface and set it as the global handler for the input in LibGDX
by calling Gdx.input.setInputProcessor() .
Reading the keyboard/touch/mouse input
Query the system for the last x or y coordinate in the screen coordinates, where the
screen origin is at the top-left corner by calling either Gdx.input.getX() or Gdx.
input.getY() . The different conditions are as follows:
• To find out whether the screen is touched either by a finger or by mouse,
call Gdx.input.isTouched()
• To find out whether the mouse button is pressed, call Gdx.input.
isButtonPressed()
• To find out whether the keyboard key is pressed, call Gdx.input.
isKeyPressed()
Reading the accelerometer
Query the accelerometer for its value on the x axis by calling Gdx.input.
getAccelerometerX() . Replace X in the method's name with Y or Z to query the
other two axes. Be aware that there will be no accelerometer present on a desktop,
so LibGDX always returns 0 .
Starting and canceling vibrator
On Android, you can let the device vibrate by calling Gdx.input.vibrate() .
A running vibration can be canceled by calling Gdx.input.cancelVibrate() .
 
Search WWH ::




Custom Search