Last active
August 29, 2015 14:18
-
-
Save terebentina/62523767a5c80c941679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener("blur", function () { | |
if (me.sys.stopOnBlur) { | |
me.state.stop(true); | |
} | |
if (me.sys.pauseOnBlur) { | |
// terebentina | |
me.sys.pauseOnBlurContext = me.state.isPaused(); // save the current isPaused state so we know what to resume to | |
me.state.pause(true); | |
} | |
}, false); | |
// set restart/resume action on gaining focus | |
window.addEventListener("focus", function () { | |
if (me.sys.stopOnBlur) { | |
me.state.restart(true); | |
} | |
// terebentina: resume the paused game only if it wasn't already paused when the window was blurred | |
if (me.sys.resumeOnFocus && !me.sys.pauseOnBlurContext) { | |
me.state.resume(true); | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment