Sign in to follow this  
Nicholas Kong

How to create an efficient Game Menu System

Recommended Posts

Nicholas Kong    1535

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?

 

[URL=http://s33.photobucket.com/user/warnexus/media/menuTest_zps34954ddb.png.html]menuTest_zps34954ddb.png[/URL]

Share this post


Link to post
Share on other sites
Rorakin    618

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
Nicholas Kong    1535

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
micecd    101

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this