Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I know that's it's easy to make buttons that highlight when you move your mouse over them, but when it comes to sub-menus I'm kinda stuck. Anyone got some tips on the best way to have a main menu with sub-menus? (like Singleplayer -> Load Save -> Save 1-5? -> Start game etc.)

share|improve this question

3 Answers 3

up vote 11 down vote accepted

This is usually done using a stack of game states. For example, each item listed above would be pushed onto a stack as follows:

  • Gameplay
  • Select Save
  • Single Player
  • Main Menu

Where each state on the stack references its sub-items. When a button is clicked, it's corresponding state is pushed onto the stack, and becomes the top-most item which is drawn and interacted with. Usually, you would only draw that top state, unless there is some kind of transparency between layers, in which case you would draw from the bottom of the stack up until you draw the active state.

share|improve this answer
    
This is the clearest answer, thanks! –  Dlaor Aug 10 '10 at 13:10
    
If you want some more ideas about game state stacks, there's this question: gamedev.stackexchange.com/questions/1783/game-state-stack –  The Communist Duck Aug 10 '10 at 13:35

"Best way" is entirely subjective. Look at the way other games do it and see if you find one that works well. The one thing you absolutely need is a way for the user to hit Cancel and get back to the previous level. You can give each menu object a reference back to the menu it was opened from, or implement it with a stack.

Aside from that, it all depends on what your game feels like and what you want your menus to feel like. Should each menu take up the entire screen, Final Fantasy style? Should they branch off of each other like Windows submenus? Should you go for something exotic like radial menus? It's up to you, really.

share|improve this answer

You should definitely implement it as either a Finite-state machine (FSM) or a Stack of states (sub-menus), depending on the exact requirements. Whichever sub-menu is the current one in the FSM or the top one on the stack, draws to the screen and handles input. And then when it detects the user clicks a button, it switches the FSM or pushes onto the stack the correct state to go to that next screen.

In your case I'm thinking a Stack is best, but if you had a more complex menu system that jumped around menus arbitrarily then you'd want to use a FSM.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.