From cbefe77af7cb8049a6678ee92fcc7a721b92b1a9 Mon Sep 17 00:00:00 2001 From: Thepuppetqueen57 Date: Mon, 23 Feb 2026 23:23:40 -0800 Subject: [PATCH] Made menu music keep playing across all scenes but game this was way more annoying than it should have been. Wanna know why? Godot. --- Scenes/MainMenu.tscn | 34 ++++++++++++----------------- Scripts/MusicManager.cs | 43 +++++++++++++++++++++++++++++++++++++ Scripts/MusicManager.cs.uid | 1 + project.godot | 1 + 4 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 Scripts/MusicManager.cs create mode 100644 Scripts/MusicManager.cs.uid diff --git a/Scenes/MainMenu.tscn b/Scenes/MainMenu.tscn index 419a09d..0b0ddd0 100644 --- a/Scenes/MainMenu.tscn +++ b/Scenes/MainMenu.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=11 format=3 uid="uid://bg4fa11htun38"] +[gd_scene format=3 uid="uid://bg4fa11htun38"] [ext_resource type="Script" uid="uid://cyo278cd6hfm" path="res://Scripts/FirstLoad.cs" id="1_ghw46"] [ext_resource type="FontFile" uid="uid://dq7nkk7n7wrq4" path="res://Fonts/Lexend.ttf" id="1_tt5f1"] [ext_resource type="Script" uid="uid://bc4miccifwrk0" path="res://Scripts/SceneSwitcher.cs" id="2_8saeu"] -[ext_resource type="AudioStream" uid="uid://6v4630hrkeg6" path="res://Audio/Music/Menu.mp3" id="2_853f1"] [sub_resource type="LabelSettings" id="LabelSettings_tt5f1"] font = ExtResource("1_tt5f1") @@ -44,7 +43,7 @@ corner_radius_top_right = 5 corner_radius_bottom_right = 5 corner_radius_bottom_left = 5 -[node name="MainMenu" type="Control"] +[node name="MainMenu" type="Control" unique_id=636482050] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -53,7 +52,7 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_ghw46") -[node name="Center" type="Control" parent="."] +[node name="Center" type="Control" parent="." unique_id=1489292265] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 @@ -67,7 +66,7 @@ offset_bottom = 20.0 grow_horizontal = 2 grow_vertical = 2 -[node name="Title" type="Control" parent="Center"] +[node name="Title" type="Control" parent="Center" unique_id=57661156] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 @@ -81,7 +80,7 @@ offset_bottom = -78.0 grow_horizontal = 2 grow_vertical = 2 -[node name="Main" type="Label" parent="Center/Title"] +[node name="Main" type="Label" parent="Center/Title" unique_id=1207683741] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 @@ -102,7 +101,7 @@ label_settings = SubResource("LabelSettings_tt5f1") horizontal_alignment = 1 vertical_alignment = 1 -[node name="GodotText" type="Label" parent="Center/Title"] +[node name="GodotText" type="Label" parent="Center/Title" unique_id=403155134] modulate = Color(0.3019, 0.560815, 0.753292, 1) layout_mode = 1 anchors_preset = 8 @@ -123,7 +122,7 @@ text = "Godot" horizontal_alignment = 1 vertical_alignment = 1 -[node name="Buttons" type="Control" parent="Center"] +[node name="Buttons" type="Control" parent="Center" unique_id=2095190478] layout_mode = 1 anchors_preset = 8 anchor_left = 0.5 @@ -137,7 +136,7 @@ offset_bottom = 20.0 grow_horizontal = 2 grow_vertical = 2 -[node name="HBoxContainer" type="HBoxContainer" parent="Center/Buttons"] +[node name="HBoxContainer" type="HBoxContainer" parent="Center/Buttons" unique_id=1050417050] layout_mode = 1 anchors_preset = 5 anchor_left = 0.5 @@ -149,7 +148,7 @@ offset_bottom = 138.0 grow_horizontal = 2 theme_override_constants/separation = 30 -[node name="Play" type="Button" parent="Center/Buttons/HBoxContainer"] +[node name="Play" type="Button" parent="Center/Buttons/HBoxContainer" unique_id=2304701] custom_minimum_size = Vector2(500, 0) layout_mode = 2 theme_override_colors/font_color = Color(0, 0, 0, 1) @@ -167,7 +166,7 @@ text = "Play" script = ExtResource("2_8saeu") ScenePath = "res://Scenes/Game.tscn" -[node name="Settings" type="Button" parent="Center/Buttons/HBoxContainer"] +[node name="Settings" type="Button" parent="Center/Buttons/HBoxContainer" unique_id=1480005274] custom_minimum_size = Vector2(500, 0) layout_mode = 2 theme_override_colors/font_color = Color(0, 0, 0, 1) @@ -186,7 +185,7 @@ text = "Settings" script = ExtResource("2_8saeu") ScenePath = "res://Scenes/Settings.tscn" -[node name="VersionText" type="Control" parent="."] +[node name="VersionText" type="Control" parent="." unique_id=949548132] layout_mode = 1 anchors_preset = 1 anchor_left = 1.0 @@ -195,7 +194,7 @@ offset_left = -40.0 offset_bottom = 40.0 grow_horizontal = 0 -[node name="Version" type="Label" parent="VersionText"] +[node name="Version" type="Label" parent="VersionText" unique_id=520173226] layout_mode = 0 offset_left = -680.0 offset_top = 24.0 @@ -207,7 +206,7 @@ theme_override_font_sizes/font_size = 81 text = "Version: {Version Number}" horizontal_alignment = 2 -[node name="LatestVersion" type="Label" parent="VersionText"] +[node name="LatestVersion" type="Label" parent="VersionText" unique_id=463446398] layout_mode = 0 offset_left = -880.0 offset_top = 104.0 @@ -219,9 +218,4 @@ theme_override_font_sizes/font_size = 81 text = "Latest Version: {Version Number}" horizontal_alignment = 2 -[node name="HTTPRequest" type="HTTPRequest" parent="VersionText/LatestVersion"] - -[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] -stream = ExtResource("2_853f1") -autoplay = true -parameters/looping = true +[node name="HTTPRequest" type="HTTPRequest" parent="VersionText/LatestVersion" unique_id=558472309] diff --git a/Scripts/MusicManager.cs b/Scripts/MusicManager.cs new file mode 100644 index 0000000..89238b8 --- /dev/null +++ b/Scripts/MusicManager.cs @@ -0,0 +1,43 @@ +using Godot; + +public partial class MusicManager : Node { + private AudioStreamPlayer _player; + private Node _lastScene; + private AudioStream _menuMusic; + + public override void _Ready() { + _player = new AudioStreamPlayer(); + AddChild(_player); + + _menuMusic = GD.Load("res://Audio/Music/Menu.mp3"); + + _player.Stream = _menuMusic; + _player.Play(); + + _lastScene = GetTree().CurrentScene; + } + + public override void _Process(double delta) { + Node currentScene = GetTree().CurrentScene; + + if (currentScene != _lastScene) { + OnSceneChanged(currentScene); + _lastScene = currentScene; + } + } + + private void OnSceneChanged(Node newScene) { + if (_player == null) return; + if (newScene == null) return; + + if (newScene.Name == "Game") { + if (_player.Playing) + _player.Stop(); + } else { + if (_player.Stream != _menuMusic || !_player.Playing) { + _player.Stream = _menuMusic; + _player.Play(); + } + } + } +} \ No newline at end of file diff --git a/Scripts/MusicManager.cs.uid b/Scripts/MusicManager.cs.uid new file mode 100644 index 0000000..bda1563 --- /dev/null +++ b/Scripts/MusicManager.cs.uid @@ -0,0 +1 @@ +uid://cke40vv76wbqq diff --git a/project.godot b/project.godot index 64d9fb4..a4550de 100644 --- a/project.godot +++ b/project.godot @@ -23,6 +23,7 @@ config/icon="res://icon.png" [autoload] Globals="*res://Scripts/Globals.cs" +MusicManager="*uid://cke40vv76wbqq" [display]