-
Notifications
You must be signed in to change notification settings - Fork 1
/
BGM.gd
36 lines (31 loc) · 832 Bytes
/
BGM.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
extends AudioStreamPlayer
onready var tween = get_node("Tween")
func fadeout(duration = 1.0):
if duration > 0:
tween.interpolate_property(self, "volume_db", 0, -80.0, duration, Tween.EASE_IN_OUT)
tween.start()
yield(tween, "tween_all_completed")
volume_db = -80.0
stop()
yield(get_tree(), "idle_frame")
func fadein(duration = 1.0):
if duration > 0:
volume_db = -80.0
play()
tween.interpolate_property(self, "volume_db", -80.0, 0.0, duration, Tween.EASE_IN_OUT)
tween.start()
yield(tween, "tween_all_completed")
else:
play()
volume_db = 0
yield(get_tree(), "idle_frame")
func change_song(song, fade = 0.3):
if stream == song:
if not playing:
volume_db = 0
play()
return
yield(fadeout(fade), "completed")
stream = song
yield(get_tree(), "idle_frame")
yield(fadein(fade), "completed")