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 music_player: AudioStreamPlayer
|
||||||
var ui_click_player: AudioStreamPlayer
|
var ui_click_player: AudioStreamPlayer
|
||||||
|
var click_stream: AudioStream
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
music_player = AudioStreamPlayer.new()
|
music_player = AudioStreamPlayer.new()
|
||||||
@@ -14,13 +15,14 @@ func _ready():
|
|||||||
ui_click_player.bus = "SFX"
|
ui_click_player.bus = "SFX"
|
||||||
add_child(ui_click_player)
|
add_child(ui_click_player)
|
||||||
|
|
||||||
|
click_stream = load(UI_CLICK_SOUND_PATH)
|
||||||
|
|
||||||
var orig_stream = _load_stream()
|
var orig_stream = _load_stream()
|
||||||
if not orig_stream:
|
if not orig_stream:
|
||||||
push_error("Failed to load music stream: %s" % MUSIC_PATH)
|
push_error("Failed to load music stream: %s" % MUSIC_PATH)
|
||||||
return
|
return
|
||||||
|
|
||||||
var stream = orig_stream.duplicate(true) as AudioStream
|
var stream = orig_stream.duplicate(true) as AudioStream
|
||||||
|
|
||||||
_configure_stream_loop(stream)
|
_configure_stream_loop(stream)
|
||||||
music_player.stream = stream
|
music_player.stream = stream
|
||||||
_configure_audio_bus()
|
_configure_audio_bus()
|
||||||
@@ -67,7 +69,7 @@ func _stop_music() -> void:
|
|||||||
music_player.stop()
|
music_player.stop()
|
||||||
|
|
||||||
func play_ui_click() -> void:
|
func play_ui_click() -> void:
|
||||||
var click_stream = load(UI_CLICK_SOUND_PATH)
|
if not click_stream:
|
||||||
if click_stream and click_stream is AudioStream:
|
return
|
||||||
ui_click_player.stream = click_stream
|
ui_click_player.stream = click_stream
|
||||||
ui_click_player.play()
|
ui_click_player.play()
|
||||||
|
|||||||
Reference in New Issue
Block a user