2 Replies - 1612 Views - Last Post: 08 April 2013 - 12:49 AM

#1 CplUSMC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 27-February 13

Help with menu selection in XNA

Posted 03 April 2013 - 03:51 PM

I am making a main menu game state and have come across a problem. I have two textures for each button in order to indicate which button is currently selected. The problem I have is when the player presses the down key from the first button, it doesn't stop at the middle button, but goes all the way down to the third button. How can I have it pause at the middle button, before going down to the bottom button?

        //Menu selections
        private void MainMenuSelection()
        {

            KeyboardState currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            // If player presses down arrow, select credits
            if (currentKeyboardState.IsKeyDown(Keys.Down) && !previousKeyboardState.IsKeyDown(Keys.Down))
            {
                playButton.active = false;
                creditsButton.active = true;
            }

            // If player presses down again, highlight exit
            if (currentKeyboardState.IsKeyDown(Keys.Down) && ! previousKeyboardState.IsKeyDown(Keys.Down))
            {
                creditsButton.active = false;
                exitButton.active = true;
            }

            previousKeyboardState = currentKeyboardState;
        }



Is This A Good Question/Topic? 0
  • +

Replies To: Help with menu selection in XNA

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9392
  • View blog
  • Posts: 35,273
  • Joined: 12-June 08

Re: Help with menu selection in XNA

Posted 03 April 2013 - 09:50 PM

Typically I would have my menu items encoded to a number.. the top being 0, next is 1, third is 2, etc.. and each time the arrow is pressed it increments (or wraps back to zero) a counter... in the draw it checks the counter's variable and "highlights" that menu item.
Was This Post Helpful? 0
  • +
  • -

#3 oyyou  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 184
  • Joined: 26-April 10

Re: Help with menu selection in XNA

Posted 08 April 2013 - 12:49 AM

There is a very good tutorial here that I always refer to when making a main menu.
It shows you how to make a game state management and input library which is pretty useful for near enough any game you may be creating.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1