Skip to content

Commit ae3f862

Browse files
committed
Update audio manager, update Button on focus
1 parent 591bd67 commit ae3f862

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

assets/MinimalUI/MinimalUI.tres

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ border_color = Color(0.282353, 0.282353, 0.282353, 1)
1313

1414
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8fanu"]
1515
bg_color = Color(0.145098, 0.145098, 0.145098, 1)
16+
border_width_left = 1
17+
border_width_top = 1
18+
border_width_right = 1
19+
border_width_bottom = 1
1620

1721
[sub_resource type="StyleBoxFlat" id="3"]
1822
bg_color = Color(0, 0, 0, 1)
@@ -23,7 +27,7 @@ border_width_bottom = 1
2327
border_color = Color(1, 1, 1, 1)
2428

2529
[sub_resource type="StyleBoxFlat" id="4"]
26-
bg_color = Color(0.129412, 0.129412, 0.129412, 1)
30+
bg_color = Color(0.497474, 0.497474, 0.497474, 1)
2731
border_width_left = 1
2832
border_width_top = 1
2933
border_width_right = 1

scripts/audio_manager.gd

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
extends Node
2+
var num_effect_players = 64
3+
var available: Array = [] # The available players.
4+
var queue: Array = [] # The queue of sounds to play.
25

36
@onready var music_player: AudioStreamPlayer = $MusicPlayer
47
@onready var sound_player: AudioStreamPlayer = $SoundPlayer
58

69
func _ready():
7-
pass # Replace with function body.
10+
# Create the pool of AudioStreamPlayer nodes.
11+
for i in num_effect_players:
12+
var p = AudioStreamPlayer.new()
13+
add_child(p)
14+
available.append(p)
15+
p.finished.connect(_on_stream_finished.bind(p))
16+
p.bus = "Sound Effect"
17+
18+
func play(sound_path):
19+
# Not to queue too many sounds in a short time interval
20+
if len(queue) <= num_effect_players:
21+
queue.append(sound_path)
22+
23+
func _process(_delta):
24+
# Play a queued sound if any players are available.
25+
if not queue.is_empty() and not available.is_empty():
26+
available[0].stream = load(queue.pop_front())
27+
available[0].play()
28+
available.pop_front()
829

930
func play_button_sound():
1031
sound_player.play()
1132

1233
func play_music_sound():
1334
music_player.play()
35+
36+
func stop_music():
37+
music_player.stop()
38+
39+
func _on_stream_finished(stream):
40+
# When finished playing a stream, make the player available again.
41+
available.append(stream)

0 commit comments

Comments
 (0)