diff --git a/source/funkin/play/PauseSubState.hx b/source/funkin/play/PauseSubState.hx index 195f94139..695a4b920 100644 --- a/source/funkin/play/PauseSubState.hx +++ b/source/funkin/play/PauseSubState.hx @@ -1026,9 +1026,9 @@ class PauseSubState extends MusicBeatSubState #if FEATURE_MOBILE_ADVERTISEMENTS AdMobUtil.removeBanner(); #end - 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(); } } diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 9a3f7039e..5bb3fa44c 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -8,6 +8,7 @@ import flixel.FlxObject; import flixel.FlxSubState; import flixel.math.FlxMath; import flixel.math.FlxPoint; +import flixel.sound.FlxSound; import flixel.text.FlxText; import flixel.tweens.FlxTween; import flixel.tweens.FlxEase; @@ -449,6 +450,11 @@ class PlayState extends MusicBeatSubState */ var cameraTweensPausedBySubState:List = new List(); + /** + * Track any sounds we've paused for a Pause substate, so we can unpause them when we return. + */ + var soundsPausedBySubState:List = new List(); + /** * False until `create()` has completed. */ @@ -891,7 +897,6 @@ class PlayState extends MusicBeatSubState super.update(elapsed); - var list = FlxG.sound.list; updateHealthBar(); updateScoreText(); @@ -1361,9 +1366,25 @@ class PlayState extends MusicBeatSubState musicPausedBySubState = true; } - // Pause vocals. - // Not tracking that we've done this via a bool because vocal re-syncing involves pausing the vocals anyway. - if (vocals != null) vocals.pause(); + // 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. + if (Std.isOfType(subState, PauseSubState)) + { + FlxG.sound.list.forEachAlive(function(sound:FlxSound) { + // The need to check for time is obligatory because of scheduled sounds + if (!sound.active || sound == FlxG.sound.music || (!sound.playing && sound.time >= 0)) return; + sound.pause(); + 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. @@ -1419,6 +1440,8 @@ class PlayState extends MusicBeatSubState musicPausedBySubState = false; } + forEachPausedSound((s) -> needsReset ? s.destroy() : s.resume()); + // Resume camera tweens if we paused any. for (camTween in cameraTweensPausedBySubState) { @@ -3423,6 +3446,8 @@ class PlayState extends MusicBeatSubState } } + forEachPausedSound((s) -> s.destroy()); + // Remove reference to stage and remove sprites from it to save memory. if (currentStage != null) { @@ -3731,6 +3756,15 @@ class PlayState extends MusicBeatSubState scrollSpeedTweens = []; } + function forEachPausedSound(f:FlxSound->Void):Void + { + for (sound in soundsPausedBySubState) + { + f(sound); + } + soundsPausedBySubState.clear(); + } + #if FEATURE_DEBUG_FUNCTIONS /** * Jumps forward or backward a number of sections in the song.