Sorry if this is a little bit out of order, but it is a complex topic…
While working on a pause button for Evoli, we realised that the pause button should control the game states.
The button should display ‘Play’ when the game is in the pause state and display ‘Pause’ when the game is in the main state. Clicking on ‘Pause’ should push the pause state on the stack and clicking on ‘Play’ would pop the pause state.
In addition, pressing
P should toggle between the two states. This can be done in
The first question was, how to change the state from within the UI system. After browsing the examples, I stumbled upon
TransEvent and realised that it is possible to use
TransEvent to change the state from within a system.
But after further investigation, I stumbled on the PR regarding communication between state and systems using resources: https://github.com/amethyst/amethyst/pull/1154
There are a lot of good points in that PR, but I can’t see a consensus on how communication between state and systems should be done.
The second question is how the UI system determines the current state we are in. This can be done using resources (enums or boolean flags per state).
Some of my notes:
- Systems should not know about the states and rely on resources only (But why)
- Systems run by the game data dispatcher might know about states since they are independent of them.
- The only responsibility of states is to run the dispatchers and perform transitions
- State-specific systems should not use
TransEvent, because they will stop themselves, so they can only do transitions one-way.
There will be three states:
- Menu state
- Main state
- Paused state
The UI only exists in the main state and in the paused state, so the UI system should not be attached to the game data dispatcher because it should not run in the menu state.
Instead, the main state should have two dispatchers. One for the game and one for the UI and the UI dispatcher runs in
So we have systems specific to states, systems that run in shadow update and also global game data systems. I feel like that is too specific and in that case, tightly coupling a system to states and using
TransEvent should be fine.