-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio.gd
37 lines (26 loc) · 837 Bytes
/
audio.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
extends Node
var num_players = 8
var bus = "master"
var available = [] # The available players.
var queue = [] # The queue of sounds to play.
signal finished_sound
func _ready():
# Create the pool of AudioStreamPlayer nodes.
for i in num_players:
var p = AudioStreamPlayer.new()
add_child(p)
available.append(p)
p.connect("finished", self, "_on_stream_finished", [p])
p.bus = bus
func _on_stream_finished(stream):
get_tree().get_root().get_node("Main").resume_bgm()
available.append(stream)
func play(sound_path):
get_tree().get_root().get_node("Main").pause_bgm()
queue.append(sound_path)
func _process(delta):
# Play a queued sound if any players are available.
if not queue.empty() and not available.empty():
available[0].stream = load(queue.pop_front())
available[0].play()
available.pop_front()