Skip to content

Main Menu

Ujjen edited this page Nov 13, 2023 · 1 revision

Overview

This Godot 4 script represents the main menu scene for a game. It extends the Control class and provides functionality for handling user interactions within the main menu. The menu includes options for starting a new game, accessing settings such as video and audio preferences, and quitting the game.

Variables

  • game_manager

Type: FinalGame

Description: Reference to the FinalGame class used in the project.

  • menu, options, video, audio

Type: Control

Description: References to UI elements in the main menu, options menu, video options menu, and audio options menu, respectively.

Methods

_ready()

Description: Called when the node enters the scene tree for the first time. Sets focus on the start button for user interaction.

_process(delta)

Parameters:

delta: Elapsed time since the previous frame.

Description: Called every frame. Toggles menu visibility and pauses the game on 'ui_cancel' input.

toggle()

Description: Toggles menu visibility and pauses the game.

_on_start_pressed()

Description: Initiates a new game when the start button is pressed.

show_and_hide(first, second)

Parameters:

  • first: Control - The menu screen to show.
  • second: Control - The menu screen to hide.

Description: Shows and hides different menu screens.

_on_options_pressed()

Description: Switches to the options menu when the options button is pressed.

_on_quit_pressed()

Description: Exits the game when the quit button is pressed.

_on_video_pressed()

Description: Switches to the video options menu when the video button is pressed.

_on_audio_pressed()

Description: Switches to the audio options menu when the audio button is pressed.

_on_back_pressed()

Description: Returns to the main menu from any sub-menu when the back button is pressed.

_on_backfromvideo_pressed()

Description: Returns to the options menu from the video options menu when the back button is pressed.

_on_back_from_audio_pressed()

Description: Returns to the options menu from the audio options menu when the back button is pressed.

_on_full_screen_toggled(button_pressed)

Parameters:

button_pressed: bool - The state of the full-screen toggle button.

Description: Adjusts the window size based on the state of the full-screen toggle button.

_on_v_sync_toggled(button_pressed)

Parameters:

button_pressed: bool - The state of the V-sync toggle button.

Description: Adjusts the V-sync mode based on the state of the V-sync toggle button.

volume(bus_index, value)

Parameters:

bus_index: int - The index of the audio bus.

value: float - The volume level in decibels.

Description: Adjusts the volume on the specified audio bus.

_on_master_value_changed(value)

Parameters:

value: float - The master volume level.

Description: Adjusts the master volume based on the slider value, with an option to mute.

Clone this wiki locally