Skip to content

Commit a0d67a1

Browse files
authored
Merge pull request #46 from Project-Funk-Engine/SceneTransition
Scene transition
2 parents 3b73620 + b67fb1f commit a0d67a1

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config_version=5
1111
[application]
1212

1313
config/name="Funk Engine"
14-
run/main_scene="res://scenes/BattleDirector/test_battle_scene.tscn"
14+
run/main_scene="res://scenes/TestTransition/testTransition.tscn"
1515
config/features=PackedStringArray("4.3", "C#", "Forward Plus")
1616
config/icon="res://icon.svg"
1717

scenes/BattleDirector/test_battle_scene.tscn

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[gd_scene load_steps=7 format=3 uid="uid://b0mrgr7h0ty1y"]
1+
[gd_scene load_steps=10 format=3 uid="uid://b0mrgr7h0ty1y"]
22

33
[ext_resource type="Script" path="res://scenes/BattleDirector/scripts/BattleDirector.cs" id="1_cwqqr"]
44
[ext_resource type="PackedScene" uid="uid://dfevfib11kou1" path="res://scenes/ChartViewport/ChartViewport.tscn" id="2_cupb3"]
55
[ext_resource type="Script" path="res://scenes/BattleDirector/scripts/Conductor.cs" id="2_pcp76"]
66
[ext_resource type="Texture2D" uid="uid://ci0g72j8q4ec2" path="res://scenes/BattleDirector/assets/CoolBG.jpg" id="4_13o87"]
77
[ext_resource type="PackedScene" uid="uid://duhiilcv4tat3" path="res://scenes/BattleDirector/NotePlacementBar.tscn" id="7_3ko4g"]
88
[ext_resource type="AudioStream" uid="uid://cv6lqjj6lu36h" path="res://Audio/335571__magntron__gamemusic_120bpm.mp3" id="8_caqms"]
9+
[ext_resource type="Script" path="res://scripts/SceneChange.cs" id="9_bxa6e"]
910

1011
[node name="ProtoBattleDirector" type="Node2D" node_paths=PackedStringArray("CM", "NotePlacementBar", "CD", "Audio")]
1112
script = ExtResource("1_cwqqr")
@@ -48,6 +49,20 @@ offset_top = 164.0
4849
offset_right = 16.0
4950
offset_bottom = 164.0
5051

52+
[node name="Control" type="Control" parent="."]
53+
layout_mode = 3
54+
anchors_preset = 0
55+
offset_right = 40.0
56+
offset_bottom = 40.0
57+
58+
[node name="Button" type="Button" parent="Control"]
59+
layout_mode = 0
60+
offset_right = 8.0
61+
offset_bottom = 8.0
62+
text = "Return to Title"
63+
script = ExtResource("9_bxa6e")
64+
ScenePath = "res://scenes/TestTransition/testTransition.tscn"
65+
5166
[node name="TempRelicList" type="Label" parent="."]
5267
offset_left = 564.0
5368
offset_top = 165.0

scenes/ChartViewport/ChartManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,15 @@ private NoteArrow CreateNote(ArrowType arrow, int beat = 0)
127127
newArrow.Position += Vector2.Right * newArrow.Bounds * 10; //temporary fix for notes spawning and instantly calling loop from originating at 0,0
128128
return newArrow;
129129
}
130+
131+
public override void _ExitTree()
132+
{
133+
GD.Print("[DEBUG] Stopping tweens before exiting the scene...");
134+
135+
foreach (var tween in GetTree().GetProcessedTweens())
136+
{
137+
tween.Stop();
138+
GD.Print("[DEBUG] Stopped tween.");
139+
}
140+
}
130141
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://dbeplni2du158"]
2+
3+
[ext_resource type="Script" path="res://scripts/SceneChange.cs" id="1_n6d5u"]
4+
5+
[node name="Control" type="Control"]
6+
layout_mode = 3
7+
anchors_preset = 0
8+
offset_right = 40.0
9+
offset_bottom = 40.0
10+
11+
[node name="Node2D" type="Node2D" parent="."]
12+
13+
[node name="StartButton" type="Button" parent="."]
14+
layout_mode = 0
15+
offset_left = 120.0
16+
offset_top = 56.0
17+
offset_right = 128.0
18+
offset_bottom = 64.0
19+
scale = Vector2(2.48, 2.48)
20+
text = "start battle"
21+
script = ExtResource("1_n6d5u")
22+
ScenePath = "res://scenes/BattleDirector/test_battle_scene.tscn"
23+
24+
[node name="ExitButton" type="Button" parent="."]
25+
layout_mode = 0
26+
offset_left = 471.0
27+
offset_top = 95.0
28+
offset_right = 508.0
29+
offset_bottom = 126.0
30+
scale = Vector2(2.56, 2.56)
31+
text = "exit"
32+
script = ExtResource("1_n6d5u")
33+
ScenePath = "exit"

scripts/SceneChange.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using Godot;
3+
4+
public partial class SceneChange : Button
5+
{
6+
[Export]
7+
public string ScenePath = "";
8+
9+
public override void _Ready()
10+
{
11+
Pressed += OnButtonPressed;
12+
GD.Print($"[DEBUG] Scene Path: '{ScenePath}'");
13+
}
14+
15+
private void OnButtonPressed()
16+
{
17+
//ScenePath = ScenePath.Trim('\"');
18+
if (ScenePath.ToLower() == "exit")
19+
{
20+
GD.Print("Exiting game");
21+
GetTree().Quit();
22+
return;
23+
}
24+
25+
if (string.IsNullOrEmpty(ScenePath) || !ResourceLoader.Exists(ScenePath))
26+
{
27+
GD.PrintErr($"❌ Scene not found: {ScenePath}");
28+
GD.Print($"[DEBUG] Trying to load: '{ScenePath}'");
29+
return;
30+
}
31+
32+
GD.Print($"✅ Loading scene: {ScenePath}");
33+
GetTree().ChangeSceneToFile(ScenePath);
34+
}
35+
}

0 commit comments

Comments
 (0)