Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game states
- in your game you can use special variables that you can use to switch between states.
- these states can be used to redirect flow in/out of the game "engine", in/out of a menu, or whatever.
- int G=1;
- while(bRunning) {
- if(G==1) {
- update game physics
- redraw game
- }
- if(G==2) {
- update menu physics
- redraw menu
- }
- }
- By setting G=1, the game runs normally. By setting G=2, it seamlessly switches to the menu. Importantly, the game is just suspended. It hasn't gone anywhere. The data is all still there. It's physics and drawing just stop running. You can resume it any time by setting G=1.
- Game states can be useful for menus. Or any time you want to switch between distinct parts of your game.
- You can do them more cleverly than this, like if you want to fade between game and menu, or time to lead in/out. But this should be enough to explain the basic idea.
- A state system can be used within a menu itself, to switch between submenus and display different settings. Some people like to use a stack structure, instead of a single state variable, so that POPing a state automatically returns to the previous state. Stack based state systems can be used to add layers into the foreground like a series of dialogue boxes.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement