In the previous lecture we have added to our Android game tutorial, Teki, the score and the level system. In this chapter we have added also the acceleration of the the game as well.
In this lecture we gonna add the up and down arrow. They will be touched later on when the user want to jump or crawl with Teki to avoid the barrieres front of her.
Step 1 – The Textures
In case of the up and down arrows we have an easy task. Both have only one image assets and the positions and the sizes gonna be always the same.
First we will add the 2 Textures. You can find the images in your assets folder with the name upArrow.png and downArrow.png. For them the initializations will be at the beginning of the class.
var upArrowTexture: Texture? = null
var downArrowTexture: Texture? = null
In the create() method we are going to add them the images.
upArrowTexture = Texture(“upArrow.png”)
downArrowTexture = Texture(“downArrow.png”)
Step 2 – Draw the arrows
Now we have to figure out when the arrows should be visible on the screen. It is sure that on the Main Menu screen and on the High score screen they have to be hidden. When the Game is over, then they don’t have to be visible, so only the Running game screen left. It means they are going to be visible for the user, when the game is running, so when the gameState equals to 1.
We are going add the draw() methods again in separated method. As I told you our task is easy, especially because the size of the arrows gonna be circles, so the width and the height will be the same and the value of them will be size*2. With this value they will be enough big for the user to touch them easily.
As we have talked about already, the origin of the screen, so when the position X and Y are 0, it is at the bottom left of the screen. Knowing this information the arrows gonna be at the left side and closer to the bottom. Play with it 😉
The down arrow goes under of the up arrow, and the size gonna be the same.
Add to the gameState
After the definition of the two methods, we can add them to the gameState, when it is equal to 1.
Run the game. When you start playing, then the 2 arrows have to be visible on the screen.
Finally, as always, you can find here the whole source of the TekiTutorial::class.
I hope the description was understandable and clear. But if you have still questions, then leave me comments below! 😉
Have a nice a day! 🙂