Friday, 8 February 2013

#5.3 Tutorial (LibGDX & MTX) Game State

How to manage game state, well thanks to LibGDX Scene2D, it is very easy.


What manages my game, the GameManager. There is enum class in MTX called GameState, which has different states (You can see in the above screenshot)

The GameManager keep tracking the game state, you can set the game state or get the game state with "set/getGameState()" method in GameManager. (Actually it is in the AbstractGameManager of MTX)


In my world, I keep track game state and decide to act or not. If I do not act, everthing under the world (WorldLayers, actors, etc..) will stop acting. This can be improved and it can be changed, I just wanted to show how can it work.

  • if gameState.RUNNING, continue acting


if you tried the play/pause button on the test project you will notice everything stops moving (acting). In my GameScreen, I constructed GameManager and GameScreenMenu classes.

In my GameScreenMenu, I have reference to Screen (which has GameManager). I created a toggle button, which changes game state.

Basically I have one GameManager, and it has references everywhere (Screen, worlds, layers ...)

Well, this may not be ultimate approach or best solution, but it works great and performance is very good. At the moment, I cannot ask no more.


  1. Man !
    You are amazing !!
    just found out about your blog couple days ago and I am very impressed by what I have seen and download.

    I can't wait for Box2d tutorials, also for the freebies :P,,, I'd like to see some live wallpapers.

    Thank you very much for your effort.

    1. Thanks. I have plans for Box2D, but I am very very busy, I do my best as a single developer of MTX :D

    2. yeah I know :)
      anyway, I followed you on twitter so I'll find out each time you post.
      Thanks again.