Jump to content
  • Advertisement
Sign in to follow this  
Nicholas Kong

How to create an efficient Game Menu System

This topic is 1923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I finished implementing the current ideas of gameplay and character management mechanics of my arcade shooter in Java. Now it is time to build the game menu that links to the gameplay when the user presses the New Game button on the menu.

 

So the question I have is in regards to the buttons on the menu. Since the buttons need to act upon a certain event (like when the user presses the button) it would needs listeners which would mean it needs to be a class that implements a particular listener. So should I make the button a nested class inside the Game Menu class so it is all in one place for readability? Or should the button be a separate class? Or does it depend how many buttons the game menu would have?

 

menuTest_zps34954ddb.png

Share this post


Link to post
Share on other sites
Advertisement

There's many different ways to do it, but I don't think you need a separate class for the main menu. The main menu is just a collection of buttons that do different things.

You can create a GUI factory class that creates buttons, or just create them manually if all you have are buttons.

Your main loop should just be a finite state machine that pauses / unpauses the game and checks for input / displays different buttons depending on which state the game is in. "Main Menu" would probably be one of the states for your main loop.

Share this post


Link to post
Share on other sites

When you say a GUI factory, you mean like a constructor ? I never heard the term GUI factory class before. It seems you are referring to a constructor because the following definition seems to relate to it.

 

Why is a game loop a finite state machine? Finite State as it has limited and certain action? Why is it a machine? Interesting sleep.png

Edited by warnexus

Share this post


Link to post
Share on other sites

Have a button array, and have the constructor for the buttons by the x,y,width,height and text on the button.

 

Have the main menu class extend the menu class that you would create, and have it detect when a button has been click on.

 

What you would do is have the button class initialize a rectangle from the constructor, and upon updating, detect if the user's mouse has clicked on it.

 

If it has clicked on it, have the action lead to a boolean, and your menu class will do something if that button has been clicked.

 

For the input, make a class called input which implements all the listeners, and in your Game class, put input in statically.

Edited by micecd

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!