O'Reilly logo

Android Game Programming by Example by John Horton

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

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

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