Sound effects
This commit is contained in:
parent
6ea21b3181
commit
6671b455c4
17 changed files with 94 additions and 6 deletions
33
metroidvania/Scenes/Music/SoundFX.gd
Normal file
33
metroidvania/Scenes/Music/SoundFX.gd
Normal file
|
@ -0,0 +1,33 @@
|
|||
extends Node
|
||||
|
||||
onready var soundPlayers = get_children()
|
||||
|
||||
const SOUNDS_PATH = "res://Assets/Music and Sounds/"
|
||||
const DEFAULT_VOLUME_DB = -20
|
||||
const DEFAULT_PITCH_SCALE = 1
|
||||
|
||||
var cache = {}
|
||||
|
||||
func load_sound(filename):
|
||||
var path = SOUNDS_PATH + filename
|
||||
if not (filename in cache):
|
||||
cache[filename] = load(path)
|
||||
return cache[filename]
|
||||
|
||||
func play_fx(sound, pitch_scale = DEFAULT_PITCH_SCALE, volume_db = DEFAULT_VOLUME_DB):
|
||||
filename = sound + ".wav"
|
||||
play(load_sound(filename), pitch_scale, volume_db)
|
||||
|
||||
func play_music(sound, pitch_scale = DEFAULT_PITCH_SCALE, volume_db = DEFAULT_VOLUME_DB):
|
||||
filename = sound + ".ogg"
|
||||
play(load_sound(filename), pitch_scale, volume_db)
|
||||
|
||||
func play(sound_res, pitch_scale, volume_db):
|
||||
for soundPlayer in soundPlayers:
|
||||
if not soundPlayer.playing:
|
||||
soundPlayer.pitch_scale = pitch_scale
|
||||
soundPlayer.volume_db = volume_db
|
||||
soundPlayer.stream = sound_res
|
||||
soundPlayer.play()
|
||||
return
|
||||
print("Too many sounds")
|
Loading…
Add table
Add a link
Reference in a new issue