Making our player jump

Since in our further chapters, we will be spawning obstacles and coins randomly on the screen, we will modify our player to navigate up and down on the screen. So, let's say if you touch your screen, the player will go up and if you stop touching the screen, our player will go down. Let us take a look at the changes we need to implement in our code first and then understand them step by step by breaking them down. We will be working on the file for this code portion.

Initially, our animation used to start as soon as the game started. But we need a little bit more control over our actions so we used our getPlaying() function to achieve this. Here's how we will tackle this problem:

We added a condition in ...

Get Learning Android Game Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.