O'Reilly logo

Android Studio Game Development: Concepts and Design by J. F. DiMarzio

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

Chapter    8

Reading User Input

If you have never coded a game for a mobile device or tablet, one problem will quickly arise. Unlike for gaming consoles, or even desktops, a distinct lack of input options exist to relay your player’s intentions back into the game code. Without the benefit of game controllers, keyboards, or mice, supplying your player with a complex input system can be difficult.

The majority of your player input will come from the device’s touch screen. Wiring up your game to detect and respond to touch events on the device is not as hard as it may appear on the surface.

Using the onTouchEvent()

Within your GameView class, override the onTouchEvent() as follows:

@Overridepublic boolean onTouchEvent(MotionEvent event) {}

The ...

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