Question

I'm starting to do some menu programming for a simple game I'm making using Slick2D. My menu is essentially a list of options, which when selected, can open up a sub-menu with more options.

For example:

Main Menu
---------
New Game
Options

When Options is selected the following menu appears:

Options
-------
Video
Audio
Back

My question is should I initialize a different BasicGameState for each sub-menu or is there a better way to handle this?

Was it helpful?

Solution

State Based Games are very strictly only to be used to have separations between splash screens, "new game" menus (like a main menu), and gameplay. Having more than 3 or 4, means you're definitely using them in an inefficient way.

A BasicGameState class should contain ALL your game code, including menu interaction stuff that is available in that game state.

If you are wanting to do a menu as you describe, you would could create a class called MenuBar, and populate it with MenuItem classes, that have Item classes in them. When the menu bar is clicked at a certain x bounds, that MenuItem could have a boolean flip to true that would be for displaying it's child Item's. If the mouse is not within bounds after that, the boolean would flip to false and not draw it's Item's.

Hopefully that sets you in the right direction. Be very selective on what you want to put in BasicGameStates (I also suggest reading into what Singleton's are, as that is what BasicGameStates are: http://en.wikipedia.org/wiki/Singleton_pattern , as you should only have ONE unique type of each game state you have in your game. Thus making a separate game state for each sub menu would be very inefficient and messy to work with in the slick2d library)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top