From a37c5085c3b7ee515789d681c8c18d71071fb771 Mon Sep 17 00:00:00 2001 From: BrickPi <49528459+BrickPi@users.noreply.github.com> Date: Sun, 26 Feb 2023 10:09:13 -0600 Subject: Add Sound Effect Manager (#25) --- game/src/Autoload/SFX.gd | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 game/src/Autoload/SFX.gd (limited to 'game/src/Autoload') diff --git a/game/src/Autoload/SFX.gd b/game/src/Autoload/SFX.gd new file mode 100644 index 0000000..5299848 --- /dev/null +++ b/game/src/Autoload/SFX.gd @@ -0,0 +1,20 @@ +extends Node + +var _loaded_sfx = {} + +func _ready(): + var dir = DirAccess.open("res://audio/sfx/") + for fname in dir.get_files(): + if fname.get_extension() == "ogg": + _loaded_sfx[fname.get_basename()] = load("res://audio/sfx/" + fname) # SND-10 + +# SND-7 +func play(sound): + var player = AudioStreamPlayer.new() + player.bus = "SFX" + player.stream = _loaded_sfx[sound] + add_child(player) + player.play() + await player.finished + remove_child(player) + -- cgit v1.2.3-56-ga3b1