#Game Architecture: Game sub states?

7 messages · Page 1 of 1 (latest)

low axle
#

Hi all,

I'm creating a pause menu in my game and I'm pondering over the best solutions to use for this. As it stands, I have a GameState that handles; splash/loading, gameplay. Gameplay is currently minimal, and I'm likely to add to this list a credits and main menu state.

My question is, is it sensible to have a sub state tracker in gameplay that tracks if the game is paused or not? I've tested it and it works, I just can't decide if it's a good idea.

How would y'all solve a pause menu in game?

vivid kayak
#

There's nothing wrong with using multiple States. Using a State for pausing is a very common example of their usage. While there's many ways to use States, I prefer to think of them as a big on/off switch for certain targeted System Sets. A system for managing NPC AI could run only when GameState::Gameplay and PauseState::GameRunning while a system for playing bg music would run when just GameState::Gameplay and not care if the game was paused or not. Separate states, sub states, whatever fits the context of your project.

low axle
#

Oooh, I do like that reasoning, thanks! Just ran into a bug/issue where I had changed all my OnEnters to use the GameplayState rather than GameState, but that caused systems to run before they were ready. However your concept of on/off really helped solidify what was happening and why things broke.
Thanks!

meager oracle
#

There's a more powerful pattern for this coming in 0.14 too 🙂

low axle
#

Ooooh, exciting. I can't wait. Each migration I've hit, while huge, has been painless thanks to the migration guides

meager oracle
#

We put a ton of effort into preparing them, and I'd like to think it allows us to evolve the API in better ways