Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

DirectX ingame Menu

This topic is 2524 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

I'm currently interested in producing a menu for my program using directx. Does anyone have any advice on how they recommend setting up a menu class for creating menus?

Share this post


Link to post
Share on other sites
Advertisement
I know you are probably looking for a more in depth explanation, but this is how you would probably want to do it. You will have a function that updates your scene, a function to draw the scene, and a function to display the menu. you have a boolean variable that is true if menu is displayed and false if it is not. if the boolean variable is false, you will keep calling your update and draw scene functions. if it is true, you will skip calling your update and draw scene functions, and instead call the menu function. doing it simply like this will keep your scene the way you left it when you called the menu, so after you exit the menu, the scene will be the exact same as it was before the menu call.

You might even want to still be displaying your scene, like in the background. maybe the menu is just a little box that pops up in the middle of the screen, and maybe its transparent so you still want your scene to be drawn. if this is the case, then only skip calling the update scene function, and still call the draw and menu functions each frame while the menu boolean variable is set to true.

was that helpful? or do you want a more help on actually setting up the menu?

Share this post


Link to post
Share on other sites
You have 3 options:

1. Hardcode the ui. If you are making a fairly simple game or tool as a learning or portfolio piece, this is probably the best option. It will get you a ui fairly quickly, but it won't be flexible at all. If you have a game with one menu and the options New Game, Continue, and Quit, it would be as simple as storing an int of the currently selected menu item. If the user presses the down arrow, increment the int, if they press up decrement (and clamp it to 0-2). When drawing, draw the regular textures for 2 of the options and the selected texture for the other one based on the number.

2. Use an existing ui library. If you are creating a more complex program and need the flexibility of a real ui library, this is your choice. CEGUI is an example of a free ui framework that can plug into a directx application.

3. Create your own. Do this only if you are specifically interested in learning about ui library design.

Share this post


Link to post
Share on other sites
Turch has 3 great ideas so I'm gonna piggy-back off of him.

Another thing to look at for menus/ui is a Finite State Machine (Design Pattern). You can create a Stack that displays the current menu you have up at the top. Now say you have an options menu, simply Push your option menu state onto the stack when it is selected from the main menu. When the user exits the option menu the state should be Popped off the stack and the menu that the user was on previously (main menu, in this case) will start rendering again.

The beauty is you can make your game into it's own state. When the user hits "new game" or "continue" you just push the game state onto the stack like anything else.

It's extremely generic and easy to use if you have a good understanding of State Machines and Singletons. It works well if you want the user to be able to navigate to an Options menu from a Pause menu in game without extra overhead of each state knowing their "previous state." Instead of having to hardcode what states become active in what situations and keeping track of the previous state, it's all stored in your stack.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!