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