• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker How to run a Main Menu?

D

Dwighty4000

Guest
I just see a lot of Youtube tutorials about it but in no one is it explained how to do that the main menu should be run first before the whole game does load the room and the objects in the room.
So how do I do that the main menu is executed before the actual game? As soon as you want to start the game, you should first start in the main menu before starting the actual game from there!
To do that, I also need to know how to build that up with code as soon as I hit "new game". then a room with its corresponding objects is executed?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Make a room for the main menu, and in that room have your title object and your button objects and anything else you need to make it pretty and functional. Then in the "Play Game" button object (or whatever) just use a room_goto() call to go to the first playable room of the game.
 

Le_Beholder

Member
you can set one up by making an array for menu choices like so:
Code:
menu[0] = "New Game"
menu[1] = "Load Game"
menu[2] = "Quit Game"
menu_choice = 0;
then make some keypress up and down events that sets the menu_choice value to +1 or -1, and have a keypress letter that does the "selecting" of said menu:
Code:
if menu_choice = 2
{
game_end()
}
and as far as the Graphical User Interface goes, I made a menu graphic as a three image sprite, set the image_speed of the menu object to 0 in the create event first before anything else, and made a step event that set the image_index to whatever menu_choice was. like so:
Code:
if menu_choice = 0
{
image_index = 0;
}
the menu sprite itself is simple, you just have 3 images, each showing an arrow in front of each menu option. about as fancy as you want it.
upload_2019-11-13_12-26-43.png

thats your basic menu.
for each menu_choice action in the selector keypress event, you can plug in whatever you want.
goto_next_room(), game_end(), game_save(z_save).
edit: just be sure you arrange the images in your menu sprite to correspond to your menu_choice values.
but it shouldn't be too difficult to figure it out, since there's just three options with this example. you could go more in depth with more menu options like say... "options" for general gameplay settings, audio levels, screen size etc.
just add more "menu_choice" codes in the selector keypress event to do what you want, and dont forget to add more images to the menu sprite to show what you've "selected" as it were.
 
Last edited:

TheouAegis

Member
The Main Menu room needs to be the very first room in the resource tree (or second room if you're using a preloader room).
 

Yal

šŸ§ *penguin noises*
GMC Elder
Yeah, a menu is just a room that has menu elements instead of normal game objects. I usually have separate "setup" objects that create all data in a room before the main menu (the objects set up data and then go to the next room immediately), but that's not a big concern if you don't use a lot of big data structures and other resources that leak memory if you create them more than once - just put that in the title screen object's Create event for now. (I recommend NOT using the Game Start event because it's nice to be able to reorder rooms without breaking functionality, e.g. adding a "Made by Dwighty" splash screen right at the end and suddenly none of the level data exists when you reach the title screen anymore because the object that sets it up isn't present at the start of the game anymore...)

Protip: using the Left Mouse Pressed event, you can make objects that run code when you click on them in-game. This lets you build menus in a WYSIWYG style where you place buttons and other interface elements directly into a room the way you want the menu to appear in the game.
 

Gavolot

Member
There are actually quite a few ways to make the main menu.
If you really want to make the menu right in the game room, and not in a separate one. You can still catch all objects on the ā€œvithā€, having previously given them all the parents and for example, simply and easily make them visible equal to false.
And then draw a black rectangle on top, and on top of the rectangle show all the buttons calculating their coordinates for the "draw interface" event, for example, in the center of the screen using x and calculate your y.
And put all the menu items in a list or array.
Such a menu will be the most manageable and it will be possible to call it right during the game.

So that it is always created first, it is enough to put the menu controller as the very first object or use the room with the start code window.
 
Top