Player input
First, let's add some methods in the Player class that our input controller will be able to call, then manipulate the variables that the Player class's update method uses to move around.
We already played with the isPressingRight variable, and also have an isPressingLeft variable. Furthermore, we want to be able to jump. If you take a look at the Player class's update method, we already have the code to handle these situations. We just need the player to be able to initiate the movements via touches to the screen.
Our previous button layout design and the code we have written so far, suggests a method for going left, a method for going right, and a method for jumping.
You will also note that we pass a copy of SoundManager into the
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