Teki – The game states

Reading Time: 3 minutes
In the very last lecture we have defined the background and the movement to the left. It works pretty well, but it is annoying, that it starts running when we open the app.

To avoid this, and to get back the control of the game, we are going to define the game state. At the end it will have 4 possible values, but currently we will talk about only 2. Running, and not running.

Let’s start coding. 😉

Step 1 – Define the gameState variable

Our first step is going to be to add the gameState varible to the game. It means we will declare it at the beginning of the TekiTutorial::class.

var gameState = 0

The initial value will be 0, and it means the Main Menu screen.

Step 2 – Checking the value

In the create() method we don’t need to change the value. We will observe and modify it only in the render() method.

We are going to define in this chapter the 4 states, but as we talked about in the begin of the chapter, we will have codes only for the values of 0 and 1.

the gameState check
Relocate the backgroundX

In the previous lecture we have defined the moving background, and for that the FloatArray of backgroundX. We want to have this moving effect only when the game is running, so we are going to replace it when the gameState is equal to 1.

Repleaced for-loop

Step 2 – justTouched

The GDX library has an input option, and this has a justTouched method. We are going to implement this method inside the render method.

To observe the touches, we will have in if-statement. This will be executed, if the screen has been touched.

The justTouched method

What we want to have currently inside in this if-statement is to change the gameState to 1, so we want to start the game. In our case it means that everywhere we touch the screen, this
if-statement is going to be executed.

The justTouched method


If you have made everything correctly, then you should see this, if you run game on your device.

… and as usual, the whole 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! 🙂



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