All lessons
Lesson 15

Main Menu

Play, Options, Back. A menu is really just panels hiding and showing, with one visible at a time.

Loading the game engine. This takes a moment the first time.

A menu is really just panels hiding and showing. Only one is visible at a time. This scene has three: MenuPanel, OptionsPanel, and PlayingPanel.

The scenes

UI node · 2D node · % unique name · .tscn instanced scene

main_menu.tscn
  • MainMenu Control main_menu.gd
  • MenuPanel VBoxContainer %
  • TitleLabel Label
  • PlayButton Button %
  • OptionsButton Button %
  • QuitButton Button %
  • OptionsPanel VBoxContainer %
  • OptionsLabel Label
  • VolumeSlider HSlider
  • BackButton Button %
  • PlayingPanel VBoxContainer %
  • PlayingLabel Label
  • BackToMenuButton Button %
extends Control

func _ready() -> void:
	# Each line names the function to run when that button is clicked.
	%PlayButton.pressed.connect(_on_play_pressed)
	%OptionsButton.pressed.connect(_on_options_pressed)
	%QuitButton.pressed.connect(_on_quit_pressed)
	%BackButton.pressed.connect(_on_back_pressed)
	%BackToMenuButton.pressed.connect(_on_back_to_menu_pressed)
	# Start with only the main menu showing.
	%OptionsPanel.hide()
	%PlayingPanel.hide()

func _on_play_pressed() -> void:
	%MenuPanel.hide()
	%PlayingPanel.show()

func _on_back_to_menu_pressed() -> void:
	%PlayingPanel.hide()
	%MenuPanel.show()

func _on_options_pressed() -> void:
	%MenuPanel.hide()
	%OptionsPanel.show()

func _on_back_pressed() -> void:
	%OptionsPanel.hide()
	%MenuPanel.show()

func _on_quit_pressed() -> void:
	# A real game would call "get_tree().quit()" here to close the window.
	# This lesson goes back to the lesson list instead.
	get_tree().change_scene_to_file("res://shared/ui/lesson_select.tscn")