Robot Foot Games Helping you improve your games as we improve our own. :)

22May/112

Multiple Column Menus

This tutorial is based on theĀ Game State Management (singleplayer games) from the xna website but theĀ Network Game State Management (multiplayer games) can also be used based on your needs. There's no better place to start and if you're new to the XNA world it's a great resource to use and learn from. For this tutorial I'll be using the game state management but both should be nearly identical with the exception of the networking menus.

This tutorial focuses on adding left and right movement to your menus so you can have multiple columns of menus. Check out the video below for an example of the final product. NOTE: I have debug code in to modify the number of columns and number of menu entries just to show how you can scale it very easily. You can download the project by clicking on the zipped folder below. Left/right triggers add/remove menu entries and left/right shoulder buttons increase/decrease the number of columns.

First off open InputState.cs and we're going to replace the IsMenuUp(...) and IsMenuRigh(...) methods and add 2 new ones for our left/right movement. If you have a better way to handle the analog input (thumbsticks) than I have below please let me know!

 

Now we move onto MenuScreen.cs. Let's add this variable to the top and declare it protected so any menu screen that inherits from MenuScreen (which is all of them I believe) can change this variable to support any number of columns they would like.

In the HandleInput(...) method you have 2 if statements relating to IsMenuUp and IsMenuDown. We'll replace those with this block of code which slightly modifies them and adds input for moving left and right in our menus.

 

Move onto the Draw(...) method in MenuScreen.cs. There's a for loop here and you'll want to replace it with this code. The comments should hopefully explain what's going on some more.

 

And that's it for the code changes! To set the number of columns you want for each screen you can do it in the constructor. We'll use MainMenuScreen.cs since that's probably the easiest way to show it off. In the constructor you'll see some lines that look like this:

and you'll need to add this line after those:

 

You can change the 2 to whatever you'd like just try to be reasonable with it. If you have 100 menu entries and you try to put them in 1 column they're not going to fit very well on screen. Same goes for putting 2 menu entries in 6 columns...

Comments (2) Trackbacks (0)
  1. I would like to do something slightly different from this example, using only 1 column. If I have 10 menu entries stored in a list, how can I display the first 5. And if the user presses the left/right directional button, the first 5 menu entries transitions off and the remaining 5 transitions on?

    • The easiest way would be to make it 2 different screens with 5 menu options each. The GameStateManagement sample has built in transitions already so if you just move between the 2 screens then you’ll get the transition effect without any extra work!


Leave a comment

(required)

No trackbacks yet.