Game Menu Help, using the keyPressed method
Author |
Message |
ZZK
|
Posted: Thu Dec 23, 2010 12:23 pm Post subject: Game Menu Help, using the keyPressed method |
|
|
in my menu i have three options start, setting and quit, i need help using the arrow keys to function in the menu, so if i press down the cursor will go to options, and like that, and if i press enter the program will do the option the cursor was beside. I know this seems easy but i cant get it for the life of me, can someone please help. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: Thu Dec 23, 2010 12:52 pm Post subject: RE:Game Menu Help, using the keyPressed method |
|
|
This is how I have done it, I have no idea if Java has some built in way of doing this but w/e.
First create an array of Strings of menu options, and an integer to tell which one is selected. When down is pressed, but was not pressed last frame, you make sure increasing the selected index wont make the selected index go out of bounds, then increase it. Likewise when up is pressed, and was not pressed last frame, you make sure decreasing the selected index wont make the selected index go out of bounds, then decrease it.
For selecting entries, when enter is pressed you check if the string at the selected index is equal (I believe you have to use string's equal method) to each possible menu option. |
|
|
|
|
|
|
|