Advertisement
Sorceress

game states

Jul 22nd, 2015
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. game states
  2.  
  3. in your game you can use special variables that you can use to switch between states.
  4. these states can be used to redirect flow in/out of the game "engine", in/out of a menu, or whatever.
  5.  
  6. int G=1;
  7. while(bRunning) {
  8. if(G==1) {
  9. update game physics
  10. redraw game
  11. }
  12.  
  13. if(G==2) {
  14. update menu physics
  15. redraw menu
  16. }
  17. }
  18.  
  19. 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.
  20.  
  21. Game states can be useful for menus. Or any time you want to switch between distinct parts of your game.
  22.  
  23. 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.
  24.  
  25. 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