shard sound set to own bus and channel (fixes #53) (fixes #54)

This commit is contained in:
pennyrigate 2023-02-26 17:05:11 -05:00
parent 1b7d93195f
commit d802ce13b7
6 changed files with 33 additions and 7 deletions

View file

@ -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)

View file

@ -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"]

View file

@ -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))

View file

@ -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"

View file

@ -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

View file

@ -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