In normal application or non-animation application, we use event-driven. It means that just when there is at least one event inside event queue, the program will processes. If not, it will wait until at least one. During of that waiting time, the program does nothing.
For game, we use game loop (I saw others called it: loop-driven) because there are many things happening and need to be updated even if user did not input anything.
My question is:
With menu state (the menu for us to choose "Start new game" | "Load game" | "Continue Game" | "..." - not in-game menu/GUI), it is like normal app. It waits for user input. It does not need a real-time loop. So how we can implement it and attach it to our game?
Here is an overview of my code:
// class Game has a "StateManager" field and a loop like this
while(running)
{
-get Event
-process Event
-update
-draw
}
// inside update/draw, i simply call update/draw of "current_state" of StateManager
if the state is GamePlay, It is ok. If it is MenuState, it is my problem.