Skip to content

Commit

Permalink
fix: prevent doubled music audio
Browse files Browse the repository at this point in the history
Prevent doubled game music after player death and restart, by
stopping the game-music player before fading it in.

Prevent doubled menu music after rapidly starting the game and
returning to the menu, by stopping the menu-music player before
fading it in.
  • Loading branch information
wlsnmrk committed Dec 28, 2023
1 parent f52efbe commit 93b2d97
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/in_game_audio/InGameAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ public void OnExitTree() {

public void StartMainMenuMusic() {
GameMusic.FadeOut();
MainMenuMusic.Stop();
MainMenuMusic.FadeIn();
}

public void StartGameMusic() {
MainMenuMusic.FadeOut();
GameMusic.Stop();
GameMusic.FadeIn();
}
}
2 changes: 2 additions & 0 deletions test/src/in_game_audio/InGameAudioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void OnExitTree() {
public void PlaysMainMenuMusic() {
_logic.Setup(logic => logic.Start());
_gameMusic.Setup(music => music.FadeOut());
_mainMenuMusic.Setup(music => music.Stop());
_mainMenuMusic.Setup(music => music.FadeIn());

_audio.OnResolved();
Expand All @@ -84,6 +85,7 @@ public void PlaysMainMenuMusic() {
[Test]
public void PlaysGameMusic() {
_logic.Setup(logic => logic.Start());
_gameMusic.Setup(music => music.Stop());
_gameMusic.Setup(music => music.FadeIn());
_mainMenuMusic.Setup(music => music.FadeOut());

Expand Down

0 comments on commit 93b2d97

Please sign in to comment.