I am looking to make a menu for a game and want to use the arrow keys to go in between the options and show which option is currently selected by brackets either side. I just plain and simple don’t know where to start. Any help would be appreciated.
Unfortunately, menu and focus navigation tends to be a tricky and often non-trivial issue.
But if you’re looking for something quick, you could consider the following solution:
Look into GUI focus handling. You basically want something(probably a GUI manager class whose aware of your button widget, and the other button widgets in the GUI), to capture the input from the user indicating they want to navigate ‘up’. The quick and dirty way to do that is to check Keyboard.GetState() and look for arrow keys or any keys you think should navigate menus… or indeed gamepad buttons if you check GamePad.GetState()… look for IsKeyDown(key) for those buttons/keys. If they are, your manager class should know which widget is the next in line for focus.
Implementing the know-how of which item to navigate to can be done in many, many ways… but one way might be to used a list of widgets(the buttons in your gui). If the manager knows you’re at index 2 in the list( the third button), and the ‘down’ key is pressed, you switch focus to whatever widget is at index 3. You’ll need to check and see if the next index is out of bounds(IE, if you have 5 buttons and current selection is at 5, your index is 4, and the next index of 5 isn’t pointing to any widget)… if that’s the case, you either ignore the input, or you wrap back to index 0.
So you’ll also want to research input handling.
But yeah, maybe someone else has a really nice, clean, quick way of doing this, but input handling and GUI management tends to be a little involved.