do not reload click sound every time
This commit is contained in:
@@ -5,6 +5,7 @@ const UI_CLICK_SOUND_PATH := "res://audio/817587__silverdubloons__tick06.wav"
|
||||
|
||||
var music_player: AudioStreamPlayer
|
||||
var ui_click_player: AudioStreamPlayer
|
||||
var click_stream: AudioStream
|
||||
|
||||
func _ready():
|
||||
music_player = AudioStreamPlayer.new()
|
||||
@@ -14,13 +15,14 @@ func _ready():
|
||||
ui_click_player.bus = "SFX"
|
||||
add_child(ui_click_player)
|
||||
|
||||
click_stream = load(UI_CLICK_SOUND_PATH)
|
||||
|
||||
var orig_stream = _load_stream()
|
||||
if not orig_stream:
|
||||
push_error("Failed to load music stream: %s" % MUSIC_PATH)
|
||||
return
|
||||
|
||||
var stream = orig_stream.duplicate(true) as AudioStream
|
||||
|
||||
_configure_stream_loop(stream)
|
||||
music_player.stream = stream
|
||||
_configure_audio_bus()
|
||||
@@ -67,7 +69,7 @@ func _stop_music() -> void:
|
||||
music_player.stop()
|
||||
|
||||
func play_ui_click() -> void:
|
||||
var click_stream = load(UI_CLICK_SOUND_PATH)
|
||||
if click_stream and click_stream is AudioStream:
|
||||
if not click_stream:
|
||||
return
|
||||
ui_click_player.stream = click_stream
|
||||
ui_click_player.play()
|
||||
|
||||
Reference in New Issue
Block a user