Skip to content

Commit

Permalink
- Fix scheduled sounds still playing.
Browse files Browse the repository at this point in the history
- Change behaviour to not pause on Game Over.

This commit also does a required change which unintentionally fixes #3600.
  • Loading branch information
NotHyper-474 committed Feb 23, 2025
1 parent 93ae40e commit 22c0d9c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion source/funkin/play/PauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,9 @@ class PauseSubState extends MusicBeatSubState
*/
static function quitToChartEditor(state:PauseSubState):Void
{
state.close();
if (FlxG.sound.music != null) FlxG.sound.music.pause(); // Don't reset song position!
PlayState.instance.close(); // This only works because PlayState is a substate!
state.close();
}
}

Expand Down
41 changes: 23 additions & 18 deletions source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1215,15 +1215,24 @@ class PlayState extends MusicBeatSubState

// Pause any sounds that are playing and keep track of them.
// Vocals are also paused here but are not included as they are handled separately.
var flixelVocals = vocals?.members.map(function(voice:FunkinSound):FlxSound {
return cast voice;
});
FlxG.sound.list.forEachAlive(function(sound:FlxSound) {
if (sound != null && (sound == FlxG.sound.music || !sound.playing)) return;
sound.pause();
if (Std.isOfType(subState, PauseSubState))
{
FlxG.sound.list.forEachAlive(function(sound:FlxSound) {
// This previously only paused a sound if it was playing but scheduled sounds
// like Darnell's can kick sounds would still play after pausing.
if (sound == FlxG.sound.music) return;
sound.pause();

if (flixelVocals != null && flixelVocals.indexOf(sound) == -1) soundsPausedBySubState.add(sound);
});
soundsPausedBySubState.add(sound);
});
vocals?.forEach(function(voice:FunkinSound) {
soundsPausedBySubState.remove(voice);
});
}
else
{
vocals?.pause();
}
}

// Pause camera tweening, and keep track of which tweens we pause.
Expand Down Expand Up @@ -1335,16 +1344,6 @@ class PlayState extends MusicBeatSubState

justUnpaused = true;
}
else if (Std.isOfType(subState, GameOverSubState))
{
// Prevents a sound (like thunder) from playing after dying,
// pausing then resuming the game even though it's not supposed to.
for (sound in soundsPausedBySubState)
{
sound.kill();
}
soundsPausedBySubState.clear();
}
else if (Std.isOfType(subState, Transition))
{
// Do nothing.
Expand Down Expand Up @@ -3188,6 +3187,12 @@ class PlayState extends MusicBeatSubState
}
}

for (sound in soundsPausedBySubState)
{
sound.destroy();
}
soundsPausedBySubState.clear();

// Remove reference to stage and remove sprites from it to save memory.
if (currentStage != null)
{
Expand Down

0 comments on commit 22c0d9c

Please sign in to comment.