From d802ce13b79576b82f2b60b178a996af81ddbc53 Mon Sep 17 00:00:00 2001 From: pennyrigate Date: Sun, 26 Feb 2023 17:05:11 -0500 Subject: [PATCH] shard sound set to own bus and channel (fixes #53) (fixes #54) --- autoloads/audio.gd | 15 ++++++++++++++- autoloads/audio.tscn | 11 +++++++++-- autoloads/options.gd | 2 ++ default_bus_layout.tres | 6 ++++++ objects/collectibles/shard.gd | 4 +--- objects/collectibles/star.gd | 2 +- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/autoloads/audio.gd b/autoloads/audio.gd index a5c711c..b874b9b 100644 --- a/autoloads/audio.gd +++ b/autoloads/audio.gd @@ -2,12 +2,13 @@ extends Node #Audio Channels onready var ac_jump = $JumpSound -onready var ac_collectible = $CollecitbleSound +onready var ac_collectible = $CollectibleSound onready var ac_climb = $ClimbSound onready var ac_die = $DieSound onready var ac_music = $Music onready var ac_cheat = $CodeEntrySound onready var ac_boss = $BossSound +onready var ac_shard = $ShardSound #Sounds const a_gold = preload("res://audio/sounds/gold.wav") const a_arrow = preload("res://audio/sounds/a_egg_collect.ogg") @@ -36,3 +37,15 @@ func play_sound(snd,player): func play_music(song): if Audio.ac_music.stream != song or Audio.ac_music.playing == false: play_sound(song,ac_music) + +#Play shard sound, this silences all other sounds including music until the sound ends +func play_shard_sound(): + var idx = AudioServer.get_bus_index("sound") + AudioServer.set_bus_mute(idx, true) + ac_music.set_stream_paused(true) + play_sound(a_shard,ac_shard) + +func _on_ShardSound_finished(): + var idx = AudioServer.get_bus_index("sound") + AudioServer.set_bus_mute(idx, false) + ac_music.set_stream_paused(false) diff --git a/autoloads/audio.tscn b/autoloads/audio.tscn index 2cd210f..5000968 100644 --- a/autoloads/audio.tscn +++ b/autoloads/audio.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://autoloads/audio.gd" type="Script" id=1] +[ext_resource path="res://audio/sounds/shard.wav" type="AudioStream" id=2] [node name="Audio" type="Node"] script = ExtResource( 1 ) @@ -9,10 +10,14 @@ script = ExtResource( 1 ) volume_db = -13.5 bus = "music" -[node name="CollecitbleSound" type="AudioStreamPlayer" parent="."] +[node name="CollectibleSound" type="AudioStreamPlayer" parent="."] volume_db = -8.0 bus = "sound" +[node name="ShardSound" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 2 ) +volume_db = -8.0 + [node name="JumpSound" type="AudioStreamPlayer" parent="."] volume_db = -12.0 bus = "sound" @@ -32,3 +37,5 @@ bus = "sound" [node name="BossSound" type="AudioStreamPlayer" parent="."] volume_db = -12.0 bus = "sound" + +[connection signal="finished" from="ShardSound" to="." method="_on_ShardSound_finished"] diff --git a/autoloads/options.gd b/autoloads/options.gd index 1907b31..505f65b 100644 --- a/autoloads/options.gd +++ b/autoloads/options.gd @@ -62,3 +62,5 @@ func _set_sound_volume(value): sound_volume = value var idx = AudioServer.get_bus_index("sound") AudioServer.set_bus_volume_db(idx, linear2db(value)) + idx = AudioServer.get_bus_index("shard") + AudioServer.set_bus_volume_db(idx, linear2db(value)) diff --git a/default_bus_layout.tres b/default_bus_layout.tres index 5d90951..a252150 100644 --- a/default_bus_layout.tres +++ b/default_bus_layout.tres @@ -13,3 +13,9 @@ bus/2/mute = false bus/2/bypass_fx = false bus/2/volume_db = 0.0 bus/2/send = "Master" +bus/3/name = "shard" +bus/3/solo = false +bus/3/mute = false +bus/3/bypass_fx = false +bus/3/volume_db = 0.0 +bus/3/send = "sound" diff --git a/objects/collectibles/shard.gd b/objects/collectibles/shard.gd index 1a6f4df..94caebf 100644 --- a/objects/collectibles/shard.gd +++ b/objects/collectibles/shard.gd @@ -9,9 +9,7 @@ func _ready(): func _on_Area2D_area_entered(area): #Collect if area.is_in_group("player"): - Audio.ac_music.stream_paused = true - Audio.play_sound(Audio.a_shard,Audio.ac_collectible) - Audio.ac_collectible.connect("finished", Audio.ac_music, "set_stream_paused", [false]) + Audio.play_shard_sound() Game.score += 500 Game.shards += value Game.shards_collected[number] = true diff --git a/objects/collectibles/star.gd b/objects/collectibles/star.gd index b129feb..fae9f71 100644 --- a/objects/collectibles/star.gd +++ b/objects/collectibles/star.gd @@ -28,7 +28,7 @@ func _on_Area2D_area_entered(area): Game.stars[color] = true #5 Star reward if Game.stars[0] && Game.stars[1] && Game.stars[2] && Game.stars[3] && Game.stars[4]: - Audio.play_sound(Audio.a_shard,Audio.ac_collectible) + Audio.play_shard_sound() Game.shards += 1 Game.shards_collected[4] = true Game.score += 500