O'Reilly logo

Android Game Recipes: A Problem-Solution Approach 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     5

Reading Player Input

If this is your first time coding a game for a mobile device or tablet, you are likely to quickly notice that there is a distinct lack of input options to relay your player’s intentions back into the game code. Without the benefit of game controllers, keyboards, or mice, it can be very hard to supply your player with a complex input system.

Wiring up your game to detect and respond to touch events on the device is not as hard as it might appear on the surface.

Let’s take a look at some of the more common problems in using a touch screen as a game input.

5.1 Detect a Screen Touch

Problem

Your game is unable to detect when the player has touched the screen.

Solution

Use the onTouchEvent() to detect where and ...

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