File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ func _ready():
20
20
# 生成一个随机位置的球
21
21
func spawn_ball ():
22
22
var ball = ball_scene .instantiate ()
23
+ ball .add_to_group ("active_balls" )
23
24
add_child (ball )
24
-
25
25
# 设置随机位置
26
26
var screen_size = get_viewport ().size
27
27
var random_pos = Vector2 (
@@ -79,7 +79,17 @@ func game_over():
79
79
game_active = false
80
80
suction_level = 0
81
81
split_level = 0
82
+ $ GameOver .play ()
82
83
$ Timer .stop ()
84
+ var balls = get_tree ().get_nodes_in_group ("active_balls" )
85
+
86
+ # 批量删除
87
+ for ball in balls :
88
+ ball .queue_free () # 安全删除节点
89
+ # 可选:立即强制释放内存
90
+ Engine .get_main_loop ().process_frame # 等待一帧
91
+ RenderingServer .force_draw () # 强制渲染刷新
92
+
83
93
$ CanvasLayer/GameOverLabel .visible = true
84
94
$ CanvasLayer/RestartButton .visible = true
85
95
Original file line number Diff line number Diff line change 1
- [gd_scene load_steps =7 format =3 uid ="uid://dn5j2h175sk1p" ]
1
+ [gd_scene load_steps =8 format =3 uid ="uid://dn5j2h175sk1p" ]
2
2
3
3
[ext_resource type ="Script" path ="res://main.gd" id ="1_rstm7" ]
4
4
[ext_resource type ="Texture2D" uid ="uid://dwdx4rlggcx7d" path ="res://assets/background.jpg" id ="2_w3hb6" ]
5
5
[ext_resource type ="AudioStream" uid ="uid://b1g1mxc7vpf1f" path ="res://assets/sounds/drop.mp3" id ="3_u1754" ]
6
+ [ext_resource type ="AudioStream" uid ="uid://dxfygh5sbawso" path ="res://assets/sounds/ding.mp3" id ="4_k32rp" ]
6
7
7
8
[sub_resource type ="LabelSettings" id ="LabelSettings_nl362" ]
8
9
font_size = 32
@@ -68,6 +69,7 @@ attenuation = 0.757858
68
69
max_polyphony = 10
69
70
70
71
[node name ="GameOver" type ="AudioStreamPlayer2D" parent ="." ]
72
+ stream = ExtResource ("4_k32rp" )
71
73
72
74
[connection signal ="pressed" from ="CanvasLayer/RestartButton" to ="." method ="_on_restart_button_pressed" ]
73
75
[connection signal ="timeout" from ="Timer" to ="." method ="_on_timer_timeout" ]
You can’t perform that action at this time.
0 commit comments