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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user