Navigating between states
So far we have our state machine in place and running smoothly, the title screen starts up the program, but how to make the title screen call another state to its place when someone hits a key?
That is exactly what the StateStack
class's delayed push and pop mechanism is for. Inside a state handleEvent()
and update()
, you are given three methods to control the execution and transitions of states: requestStackPush()
, requestStackPop()
, and requestStackClear()
.
It is appropriate to use these methods to request new states to be pushed, or to show and replace the current one, as you will verify that our example states do throughout this chapter.
Creating the game state
So far we have covered the theory and practice for inserting the state stack into our sample game. It is fully functional but yet empty, so, it is finally time to create our first state, the game state.
For this, we create a class named GameState
and we proceed to relocate the code that could be found in the...