From having read a couple of the related questions posted by Joe I've identified that menu state and game state is often maintained through a stack of states. For example if the user is playing the game and brings up the menu, then after navigating around a bit the game state stack might look a little like this:
- Graphics menu
- Options menu
- Main menu
- Playing game
The game loop is then structured as single outer loop that updates the current state stack (rather than a loop for each state) - This has the added advantage of being able to cope with a far more complex menu system, for example one where multiple states are layered on top of each other, however the previous state is still visible.
while (true) {
// This example only updates the topmost state,
// however it might be necessary to perform processing on
// the other states if (for example) the menu doesn't obscure
// the entire screen and the game itself still needs drawing
Tick(GetTopmostState());
}
The following questions are related to this and cover it in more detail: