Making sense of the screen touches
We know that when the player touches the screen the operating system calls our onTouchEvent
method to give our code the opportunity to respond to the touch.
Furthermore, we have also seen that when the player touches the screen the onTouchEvent
method is called twice. We know this because of the debugging output we examined back in chapter two. You probably remember that the method is called for both the touch and release events.
To make our game respond correctly to touches we will need to first determine the actual event type and secondly find out exactly where on the screen the touch occurred.
Look at the signature of the onTouchEvent
method and pay special attention to the highlighted argument.
public boolean ...
Get Learning Java by Building Android Games - Second Edition 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.