How to manage game state, well thanks to LibGDX Scene2D, it is very easy.
GAME STATE
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)
WORLD
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
PLAY / PAUSE BUTTON and GAME MANAGER
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.
0 yorum:
Yorum Gönder