Skip to content

Commit bb38844

Browse files
committed
Use FlxG.game.lostFocus instead and check if autoPause enabled
1 parent c2ff07a commit bb38844

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

source/funkin/play/PlayState.hx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,6 @@ class PlayState extends MusicBeatSubState
390390
*/
391391
var mayPauseGame:Bool = true;
392392

393-
/**
394-
* True when the window is focused, false when not.
395-
*/
396-
var focus:Bool = true;
397-
398393
/**
399394
* The displayed value of the player's health.
400395
* Used to provide smooth animations based on linear interpolation of the player's health.
@@ -902,7 +897,8 @@ class PlayState extends MusicBeatSubState
902897
if (isInCountdown)
903898
{
904899
// Do NOT apply offsets at this point, because they already got applied the previous frame!
905-
if (focus) Conductor.instance.update(Conductor.instance.songPosition + elapsed * 1000, false);
900+
@:privateAccess
901+
if (FlxG.game._lostFocus && Preferences.autoPause) Conductor.instance.update(Conductor.instance.songPosition + elapsed * 1000, false);
906902
if (Conductor.instance.songPosition >= (startTimestamp + Conductor.instance.combinedOffset))
907903
{
908904
trace("started song at " + Conductor.instance.songPosition);
@@ -921,9 +917,9 @@ class PlayState extends MusicBeatSubState
921917
Conductor.instance.formatOffset = 0.0;
922918
}
923919

924-
if (focus) Conductor.instance.update((FlxG.sound.music.pitch != 1) ? FlxG.sound.music.time + elapsed * 1000 : (Conductor.instance.songPosition
925-
+ elapsed * 1000),
926-
false); // Normal conductor update.
920+
@:privateAccess
921+
if (FlxG.game._lostFocus && Preferences.autoPause) Conductor.instance.update((FlxG.sound.music.pitch != 1) ? FlxG.sound.music.time + elapsed * 1000
922+
: (Conductor.instance.songPosition + elapsed * 1000), false); // Normal conductor update.
927923

928924
// If, after updating the conductor, the instrumental has finished, end the song immediately.
929925
// This helps prevent a major bug where the level suddenly loops back to the start or middle.
@@ -1342,8 +1338,6 @@ class PlayState extends MusicBeatSubState
13421338
*/
13431339
public override function onFocus():Void
13441340
{
1345-
focus = true;
1346-
13471341
if (VideoCutscene.isPlaying() && FlxG.autoPause && isGamePaused) VideoCutscene.pauseVideo();
13481342
#if html5
13491343
else
@@ -1388,7 +1382,6 @@ class PlayState extends MusicBeatSubState
13881382
*/
13891383
public override function onFocusLost():Void
13901384
{
1391-
focus = false;
13921385
#if html5
13931386
if (FlxG.autoPause) VideoCutscene.pauseVideo();
13941387
#end

0 commit comments

Comments
 (0)