I could use some help, please. I’m trying to make a game with GDevelop that relies on the use of a controller, so everything has to work without a mouse or touch screen. That said, I am having trouble figuring out how to make a menu (main or pause) that runs like an old-school video game menu would. For example, the original Super Mario Bros. game allows the player to choose between a 1 or 2 player game. Or something a bit more recent, Skyrim having options for “Continue,” “Load,” etc.
I do not need to know how to make those “buttons” do different things; there are already a lot of forum threads on here about that. What I do need is help making such a menu work with a controller or keyboard. Any help is appreciated!
The way to go is I think a “selector” variable. You can image this variable as identifying the current menu. Example: every menu has a text and is named “menuentry”. Example with 5 entries:
menuentry1 is Save
menuentry2 is Load
menuentry3 is Options
menuentry4 is Super Secret Settings
menuentry5 is Quit
Now we have the “selector” variable. You handle it using events like
condition {
Up is pressed
} Then {
-1 to selector variable
}
condition{
Down is pressed
} Then {
+1 to selector variable
}
condition {
Selector variable = 6
} Then {
Set selector variable to 1
}
condition {
Selector variable = 0
} Then {
Set selector variable to 5
}
Now we want to display our choice onto the screen. We can do that in multiple way. Here I’m saying as example you have a “frame” sprite Wich is a frame around the selected option.
We put the frame at the position of our selected text objects
condition {} Then {
Set "frame" object position to "menuentry"+VariableString(selector)'s position
}
Now we have some working UI but we want it interactive. So let’s add this:
condition {
Enter/Cross/A pressed
} Then {
condition {
Variable selector = 1
} Then {
*do stuff to save the game*
}
[...]
condition {
Variable selector = 5
} Then {
Quit the Game
}
}
That’s pretty much it. For the selection you might prefer using sprites and switching animations.
This is amazing, thank you! I have seen some of your other examples on itch.io (like the Metroidvania camera one), but I didn’t check out your page specifically. This looks like what I’m hoping to do. I appreciate you taking the time for me!
I was wondering whether the use of variables in the way you’ve described would be the way to go. This is definitely worth looking into. Thank you for writing it all out for me and explaining your example. This is helpful!
To be clear, @arthuro555’s recommendation is exactly how mine works, but I just use ID variables on an object basis and a selector object. So he’s explaining it in theory and my example is it in practice. So I’m glad my method is at least in line with more experienced people’s suggestions.
The above is indeed a nice suggestion. And since it solves the “menu” problem with little effort it looks ideal.
I was a long time puzzled about the idea to have sprites as buttons and a selector variable (that kind of resembles a cursor) but have generic 2D behaviour. That means if one button is ‘selected’ and the user presses ‘right’ some other button more or less to the right of the selected button would get selected.
This seems to require direction and distance of possible targets and gets complicated - but then that might be a typical algorithm we potentially have anyway for action games, don’t we?
This is how my example works. You set up variables on each menu item saying which ID is left/right/up/down button is valid to move to. The example I’ve uploaded only has up/down in the scene, but it’s set up to work for all directions.