Adding alternative input controls

The last and rather short topic in this chapter will show you how to use the peripheral devices using the example of accelerometers, which are very common types of sensors in today's smartphones and tablets. Accelerometers are subsystems that reliably and accurately detect and measure acceleration, tilt, shock, and vibration. Basically, we just need to read the sensor data that is being measured by the accelerometer hardware and later translate the data into values and/or ranges suitable for our game.

Accelerometers in Android and iOS devices are exposed by LibGDX using the three axes x, y, and z, which can be queried via the Gdx.input module. For instance, the current acceleration value for the x axis can be easily ...

Get Learning LibGDX Game Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.