12
\$\begingroup\$

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.)

\$\endgroup\$

3 Answers 3

12
\$\begingroup\$

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.

\$\endgroup\$
1
6
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

"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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .