diff options
author | BrickPi <49528459+BrickPi@users.noreply.github.com> | 2023-02-26 17:09:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-26 17:09:13 +0100 |
commit | a37c5085c3b7ee515789d681c8c18d71071fb771 (patch) | |
tree | 7b57a387e008c168c9f4a39b123681dc684cadf2 /game/src/Autoload | |
parent | 17270d65023184bd1eed10aea223f91947bea8e8 (diff) |
Add Sound Effect Manager (#25)
Diffstat (limited to 'game/src/Autoload')
-rw-r--r-- | game/src/Autoload/SFX.gd | 20 |
1 files changed, 20 insertions, 0 deletions
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) + |