Skip to content

Instantly share code, notes, and snippets.

@terebentina
Last active August 29, 2015 14:18
Show Gist options
  • Save terebentina/62523767a5c80c941679 to your computer and use it in GitHub Desktop.
Save terebentina/62523767a5c80c941679 to your computer and use it in GitHub Desktop.
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