Skip to content

Commit 75e2e38

Browse files
authored
Add ability to stop sounds abruptly (#22)
1 parent 6ef5b11 commit 75e2e38

4 files changed

Lines changed: 35 additions & 0 deletions

File tree

addons/sound_manager/SoundManager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public static AudioStreamPlayer PlaySoundWithPitch(AudioStream resource, float p
5151
}
5252

5353

54+
public static void StopSound(AudioStream resource)
55+
{
56+
Instance.Call("stop_sound", resource);
57+
}
58+
59+
5460
public static AudioStreamPlayer PlayUISound(AudioStream resource, string overrideBus = "")
5561
{
5662
return (AudioStreamPlayer)Instance.Call("play_ui_sound", resource, overrideBus);
@@ -63,6 +69,12 @@ public static AudioStreamPlayer PlayUISoundWithPitch(AudioStream resource, float
6369
}
6470

6571

72+
public static void StopSound(AudioStream resource)
73+
{
74+
Instance.Call("stop_ui_sound", resource);
75+
}
76+
77+
6678
public static void SetDefaultSoundBus(string bus)
6779
{
6880
Instance.Call("set_default_sound_bus", bus);

addons/sound_manager/sound_effects.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ func play(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer
55
var player = prepare(resource, override_bus)
66
player.call_deferred("play")
77
return player
8+
9+
10+
func stop(resource: AudioStream) -> void:
11+
for player in busy_players:
12+
if player.stream == resource:
13+
player.call_deferred("stop")

addons/sound_manager/sound_manager.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func play_sound_with_pitch(resource: AudioStream, pitch: float = 1.0, override_b
6363
return player
6464

6565

66+
func stop_sound(resource: AudioStream) -> void:
67+
return sound_effects.stop(resource)
68+
69+
6670
func play_ui_sound(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer:
6771
return ui_sound_effects.play(resource, override_bus)
6872

@@ -73,6 +77,10 @@ func play_ui_sound_with_pitch(resource: AudioStream, pitch: float = 1.0, overrid
7377
return player
7478

7579

80+
func stop_ui_sound(resource: AudioStream) -> void:
81+
return ui_sound_effects.stop(resource)
82+
83+
7684
func set_default_sound_bus(bus: String) -> void:
7785
sound_effects.bus = bus
7886

docs/Sounds.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ Playing sound effects is broken up into playing general sounds (ie. in the game
2424

2525
Play an audio stream with a specific pitch. Optionally specify which audio bus you want to use for this sound.
2626

27+
- **`SoundManager.stop_sound(resource: AudioStream) -> void`**
28+
29+
Stop a specific audio stream.
30+
31+
2732
- **`SoundManager.play_ui_sound(resource: AudioStream, override_bus: String = "") -> AudioStreamPlayer`**
2833

2934
Play an audio stream intended for the user interface. Optionally specify which audio bus you want to use for this sound.
@@ -34,6 +39,10 @@ Playing sound effects is broken up into playing general sounds (ie. in the game
3439

3540
Play a UI audio stream with a specific pitch. Optionally specify which audio bus you want to use for this sound.
3641

42+
- **`SoundManager.stop_ui_sound(resource: AudioStream) -> void`**
43+
44+
Stop a specific audio stream.
45+
3746
- **`SoundManager.set_default_sound_bus(bus: String) -> void`**
3847

3948
Sets the default audio bus used for playing sounds.

0 commit comments

Comments
 (0)