chickensoft-games / GameDemo

The Chickensoft Game Demo — a fully tested, third-person 3D game built with Godot and C#. Now with saving and loading!
https://chickensoft.games
MIT License
322 stars 20 forks source link

Game music doubles after player death #5

Closed wlsnmrk closed 8 months ago

wlsnmrk commented 8 months ago

After the player dies (runs off the level into water), if the "Try Again" menu option is selected to restart the game, the game music doubles. It looks like the old, pre-death music stream keeps playing, while a new one is spun up in response to the game restarting.

Here's a video of the behavior: https://github.com/chickensoft-games/GameDemo/assets/23439518/8a26caa1-c7da-417f-afa9-44712d78e51c

I did a little digging and came up with some possible (simple) fixes, depending on desired behavior:

  1. Restart the music. Either:
    1. Modify InGameAudio::StartGameMusic() to call GameMusic::Stop() before GameMusic::FadeIn().
    2. Set the Max Polyphony property of the MainMenuMusic scene -- which is also used for the GameMusic node in InGameAudio -- back to 1 (currently 4), to automatically stop the first stream when the new one starts.
      • Or set the same property on the GameMusic node specifically, in the InGameAudio scene.
  2. Keep the music playing from its current position: Modify InGameAudio::StartGameMusic() to skip the call to GameMusic::FadeIn() if GameMusic::Playing is true.

I'd be happy to submit a PR if any of those are acceptable! It does seem like both options above for restarting the music would hard-stop the first stream, with no cross-fade.

jolexxa commented 8 months ago

Hey, thanks! Probably an oversight on my part. I think I was trying to make the music fade correctly and maybe didn't catch this. I think a hard stop is unavoidable if you interrupt it while its still fading, so that's fine. I don't want to mess with the polyphony, but you're welcome to try the other approaches and see what's best.