-
Notifications
You must be signed in to change notification settings - Fork 2
/
bgm_server.gd
102 lines (62 loc) · 1.88 KB
/
bgm_server.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
extends Node2D
class_name BGMServer
var music_stopped = true
enum {STAGE_1, BOSS_1}
func _ready():
$bgm02_start.stream.loop = false
$bgm03_start.stream.loop = false
AudioServer.set_bus_effect_enabled(1,0,false)
func _on_bgm02_start_finished():
if music_stopped == false:
$bgm02_loop.play()
func _on_bgm03_start_finished():
if music_stopped == false:
$bgm03_loop.play()
func change_bgm(play_next_id:int):
if PlayerVars.music:
music_stopped = true
var currently_playing_bgm
for bgm_stream in get_children():
if bgm_stream is AudioStreamPlayer:
if bgm_stream.playing == true:
currently_playing_bgm = bgm_stream
$volume_tween.interpolate_property(currently_playing_bgm, "volume_db", 0.0, -36.0, 1, Tween.TRANS_LINEAR)
$volume_tween.start()
yield($volume_tween, "tween_all_completed")
currently_playing_bgm.stop()
play_bgm(play_next_id)
else:
return
func play_bgm(bgm_id:int):
if PlayerVars.music:
match bgm_id:
STAGE_1:
$bgm02_start.play()
BOSS_1:
$bgm03_start.play()
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
music_stopped = false
else:
return
func end_fadeout(fadeout_time:float):
music_stopped = true
if PlayerVars.music:
var currently_playing_bgm
for bgm_stream in get_children():
if bgm_stream is AudioStreamPlayer:
if bgm_stream.playing == true:
currently_playing_bgm = bgm_stream
$volume_tween.interpolate_property(currently_playing_bgm, "volume_db", 0.0, -36.0, fadeout_time, Tween.TRANS_LINEAR)
$volume_tween.start()
yield($volume_tween, "tween_all_completed")
currently_playing_bgm.stop()
else:
return
func lowpass_on():
AudioServer.set_bus_effect_enabled(1,0,true)
func lowpass_off():
AudioServer.set_bus_effect_enabled(1,0,false)