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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access