State management
Think about it. If we want our game to pause, then we have to set some kind of flag that tells the game that we want it to take a break. We could set up a Boolean:
bool m_isPaused;
We would set m_isPaused
to true
if the game is paused, and set it to false
if the game is running.
The problem with this approach is that there are a lot of special cases that we may run into in a real game. At any time the game might be:
- Starting
- Ending
- Running
- Paused
These are just some example of game states. A game state is a particular mode that requires special handling. As there can be so many states, we usually create a state manager to keep track of the state we are currently in.
Creating a state manager
The simplest version of a state manager begins ...
Get OpenGL Game Development By Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.