O'Reilly logo

Learning Libgdx Game Development by Andreas Oehlke

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 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 retrieved ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required