1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-10-03 15:59:04 +00:00

Avoid unpausing music when debugger is toggled

Workaround a Flixel issue where sounds can unpause after toggling
the Flixel debugger with F2, caused by the debugger throwing a
spurious onFocus event without an onFocusLost event.
This commit is contained in:
Mike Welsh 2024-03-04 02:59:10 -08:00
parent 0a19c7a8cb
commit 5557dbf28f

View file

@ -90,6 +90,11 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
*/
var _label:String = "unknown";
/**
* Whether we received a focus lost event.
*/
var _lostFocus:Bool = false;
public function new()
{
super();
@ -177,7 +182,10 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
*/
override function onFocus():Void
{
if (!_alreadyPaused)
// Flixel can sometimes toss spurious `onFocus` events, e.g. if the Flixel debugger is toggled
// on and off. We only want to resume the sound if we actually lost focus, and if we weren't
// already paused before we lost focus.
if (_lostFocus && !_alreadyPaused)
{
resume();
}
@ -185,6 +193,7 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
{
trace('Not resuming audio on focus!');
}
_lostFocus = false;
}
/**
@ -193,6 +202,7 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
override function onFocusLost():Void
{
trace('Focus lost, pausing audio!');
_lostFocus = true;
_alreadyPaused = _paused;
pause();
}