Teki – Game Over screen

Reading Time: 3 minutes
In the very last chapter we impelmented the collision detection. This was the first step to have the Game Over screen in our app.

So this feature looks like this: when we get now the log message in the Logcat of Android Studio, then the game will be finished, so it will be stopped.

Let’s start coding. 😉

Step 1 – gameState equals to 2

The question is how we can implement the Game Over screen?! The solution is to have a new gameState. When the shapes overlap each other, then it will change the gameState to 2. When it equals to 2, then the game will be over.

The overlap inspection

So just add after the log message this line.

gameState = 2

After the set of the gameState we have to stop the timer as well. In the chapter of the implementation of the Timer() we added the stopTimer() method. Call it here also.


We have implemented already the else-statement of the Game Overs screen of the gameState in the render() method. There we have a call of the stopTimer() as well. Remove it, because we don’t need to call it twice.

Test the changes, and run the game on your device.

When the shapes overlap each other, then the game will be stopped. But we have here a problem. When the gameState equals to 2, then the barriers and the Teki won’t be visible anymore on the screen.

Extend the gameState

When gameState equals to 2, then two methods gonna be fired, the scoring() and the leveling() methods. In this way they stay visible, when the game is finished.

We have to add after this two methods the next two more methods.


for (i in 0 until numberOfBarriers)

The state of Teki won’t be changed, so we can use here the tekisStates variable as the argument.

To draw the current state of all the barriers, we need here also a for-loop from 0 until the numberOfBarriers.

Run again the app.

If you have done everything correctly, then the scores, the levels, Teki and the barriers stay visible on the screen. The arrows gonna be unvisible, but this is what we want here.

Step 2 – The Game Over Texture

In the last step of this chapter we are going ot add the Game Over Texture to the game.

As we did in the previous lectures, firstly we will add the Texture to the TekiTutorial::class.

var gameOver: Texture? = null

Then the initial value, so the image of the Game Over, we will add in the create() method. If you open the assets folder in the Android folder from the left Project menu, then you can find it under the name gameOver.png.

gameOver = Texture(“gameOver.png”)

To draw this image on the screen, we will define again a method, called drawGameOver(). This will be fired, when the gameState equals to 2. So add it to the render() method.

To have a good looking and not stretched picture, we will draw it with the width of size*6, and the height will be only one size.

The position will be at the top right corner.
You can play with the position, but be careful to have it always on the screen 🙂


Run the app. If you completed the chapter right, then you should see this screen, when you lose in the game.


If you are stucked, then you can download the whole source code at this link.

Download the tutorial


I hope the description was understandable and clear. But if you have still questions, then leave me comments below! 😉

Have a nice a day! 🙂



Click to rate this post!
[Total: 0 Average: 0]
Follow and like us:

Leave a comment

stay informed!

Subscribe to receive exclusive content and notifications