Menu Select with Arrow Keys - The easy, expandable way
|
[Written for TGF, but it probably works in MMF too]
This is one of the easiest ways to do a menu selection screen. All you need is two objects and a couple of events:
First of all, create your 'selector' object. Arrow, Crosshair, Shotgun, whatever you want - It's the item that appears next to the selected item. Now, there are two ways to proceed - Either the right way, or the longer, more complicated way. I'll outline both in case your not following instructions right
Step 1) Proper way.
Take the selector you just created and position it next to the LAST item on the 'list'. Then insert copies of it (the same object, not new ones!) next to each object, in reverse order. Example:
You game options are 'New Game', 'Load Game' and 'Quit'. Place the first arrow by Quit. Place the next one by Load, and the final by New. Do it in THAT ORDER, so that the layers come out right - because each object you add is automatically positioned to the highest layer.
Step 2) The longer, more complicated way. AKA 'Shit, I got ahead of the article' or even 'Step 1 isn't working, so i'll try this'
Just place all of your selectors next to their appropiate item. Doesn't matter in what order. Once that's done, right click on the last object and 'BRING TO FRONT'. Repeat this for each object, in reverse order. Once again, if you have 'New', 'Load' and 'Quit' - Start with Quit, then Load, then New.
Once your done with that, place a hidden counter object. Set its minimum to 0, it's inital to 1, and it's maximum to the number of selections you have PLUS ONE. Expanding on the example for New/Load/Quit, that means maximum is 4.
Reason: Items are numbered 1 - 3. End positions on the counter (0 and 4) are 'wrap' position. If the counter ends up there, it'll jump to the other end. 0 goes to 3, 4 goes to 1. That way, when you press up or down at the end of the list, it jumps instead of just sitting there.
Now to write the events. This is pretty easy:
EVENT 1:
START OF LEVEL -
Make selectors invisibe.
Spread a number: 1.
Most of you know how to set invisible. Some of you don't know spread though - Simply select the SET VALUE option for the selector. Pick 'VALUE A', and instead of SET/ADD/SUBTRACT, click the SPREAD button and use it's default value of 1. This will take all of the selectors on the main screen and assign a number to them - this is where the layer becomes important. For some reason, it starts with highest layer items and works backwards. Thats why you have to make sure that the first item is the highest, and the last is the lowest.
That handles the menu item setup. Now to handle the actual selecting.
EVENT 2:
WHEN JOYSTICK UP -
Counter: Subtract 1.
EVENT 3:
WHEN JOYSTICK DOWN -
Counter: Add 1.
That will let you move the selection up and down. But we still can't see the pointer, and it doesn't wrap! Easy.
EVENT 4:
When COUNTER = 0.
Counter: Set to 3 (Insert your maximum - 1 here).
EVENT 5:
When COUNTER = 4 (Insert your maximum here)
Counter: Set to 1.
That'll deal with the wrapping. Now to make your selector appear next to it.
EVENT 6:
When SELECTOR : VALUE A = Counter
Selector: Make Visible
That line is a little tricky too. It causes the game to look at every selector object in the frame, and ONLY pull up the one where it's A value matches the Counter. Remember how we spread a value? Yeah. Your selectors should have a number from 1 to 3 (maximum) indicating their position. Were just selecting the one that matches the counter and making it visible.
There. That's the entire arrow-driven menu system EXCEPT for the actual activation. You can do that however you want, I prefer to roll them into a disabled event group and activate it when the user presses enter. A simpler solution would be:
EVENT 7:
When ENTER is pressed AND Counter = 1.
Jump to Level X.
EVENT 8:
When ENTER is pressed AND Counter = 2.
Jump to Level X.
EVENT 9:
When ENTER is pressed AND Counter = 3.
End Game.
Got it? Good. I hope this helps some of the newer TGF users.
|
|
|