Essentially, I followed a tutorial on creating a game a while ago. The game I made now is pretty different from the tutorial I followed, but I wanted to add a main menu that allows for a play and quit. I have the buttons doing as they should, have created the signals and they respond appropriately (I think start works, but I can't confirm because the game auto launches. I confirmed that quit works because I dragged the menu I created into the game world, and when I click quit, the game quits). However, I don't want the menu in the game world on the center of the screen -- I want it to be a barrier for the player to prepare to play the game, or decide to quit the game.
So, can anyone fill me in on how I can go about adding my start menu after the fact? I'm sure its possible, but I must be missing something.
I could attach screenshots of the code, but this doesn't really show the issue I don't believe because the issue isn't with the code as far as I'm aware its more of the order of operations being out of sync. I have tried adding the game to the menu instead of vise versa but this just results with the game automatically launching and ignoring my menu.
#Issue with Main Menu
10 messages · Page 1 of 1 (latest)
So do you want to have the main menu be the screen you see by default when you open the game? If so, separate the two scenes (main menu and game world) and in project settings set the first scene to your main menu. Then, when you press quit, you quit the game (that hasn't started yet?) and if you press start, you switch the scene from the main menu to the game world. If you want, you can add an option button in the game where the player can return to the main menu.
If you want to have your main menu be a "pause" option menu where your player presses the option button and then it pauses the game, you would have to make it so that the game stops running for the time the option menu is open, and then resume the game when you continue playing. But I think you want the first option where you have to go through the main menu before getting into the game.
yes, I want to see it by default. I've created a menu in another game, but it was the first thing I did, and I had no problems with it. I recalled the information I had done prior, but in this instance I created the game first. Then I created the start menu. I created it the same way. 2dNode with two buttons attached, and a simple script written, allowing the signal from each to do what I want. So for example the quit button says
func _on_pressed_quit():
get_tree().quit()
and the play button is
func _on_play_pressed():
get_tree().change_scene_to_file("res://...") (name of my scene instead of the ellipses).
Upon pressing f5 the game just launches directly into playing as it did before. I can see that the signal connections are there and working for my game. (Indicated by what looks like wifi signal to the right of the buttons.
So in order to test that the buttons are actually working I simply dragged the menu.tscn into my game scene, and centered it. I can see the buttons, and when I click quit the game does indeed quit. However, I don't want this. I just want a simple start menu, but believe because of the way I have set it up due to working on the game first I've confused myself somewhere. I think it is something to do with the order of operations. So instead of running myGameScript.tscn first, I want it to run main.tscn first.
So yes, I would like the main menu (start menu) to be the first thing the player sees.
Project Settings > Application > Run
There you can see the Main Scene. The Main Scene is the scene that the game starts with. If you change the path there from your game to your main menu your problem should be resolved.
If you want to test a scene but don't want to go through the main menu, there is also the option to "run current scene" instead of "run project" so you can test your game scene without going through the main menu once you set the "main scene" to be the main menu
Thank you so much! I love this community, I believe you helped me last time too, and if not I thank you either way. That was such an easy fix. I appreciate that so much. I was confident the code was correct as it was incredibly similar to what I wrote before, but the issue was I had it set to launch the game first. I believe this happens when you run the game the first time?
That is the dialogue when creating a game, and you run it initailly it says something about setting the scene to be what runs first (whatever it is you created first). Thank you so much again. I truly appreciate it so much and am beyond grateful to be in such a cool community.
If you press "run project" when you haven't set any main scene, then it prompts you to ask if you want to set the current scene as main scene. It probably was there that you set the game world as main scene. But you can 1. change it later, and 2. only run the scene using "run current scene" to avoid having to set a main scene
(Totally not me that doesn't set a main scene until I created the main menu 😅 )
I am still learning about game dev. I am pretty familiar now with coding due to my degree/profession, but unfortunately my job isn't nearly as thrilling as game development. I'm much more passionate about this than looking over APIs and database management. I really enjoy making games. I thank you again. I will keep in mind to make the menu first, and in case I don't I will surely remember how to set the scene where I want now, and that I can instead use the run current scene. Thank you so so much.