true (the default) to follow the browser window, false
to leave the focus to the game's host
// YouTube Playables: only YouTube's own events pause and resume the game
me.device.setFocusEvents(false);
app.stopOnBlur = true; // a pause stops the rendering too
app.pauseOnBlur = false;
ytgame.system.onPause(() => me.event.emit(me.event.BLUR));
ytgame.system.onResume(() => me.event.emit(me.event.FOCUS));
Let the browser window report the game's focus, or leave it to the game's host (see focusEvents).
Two separate settings decide what happens when the player switches away:
blur,focusandvisibilitychangeevents the engine turns intoevent.BLURandevent.FOCUS. This function turns that on or off.pauseOnBlur,stopOnBlurandresumeOnFocusflags. They apply to everyevent.BLURandevent.FOCUS, wherever it comes from.To keep a game running while the player is away, turn the flags off (
app.pauseOnBlur = false): the window still reports, and nothing pauses.To let a host decide when the game runs, such as a web game portal's SDK (YouTube Playables forbids pausing on the page's visibility) or a native wrapper, turn this off instead and keep the flags: the window then reports nothing, the host's callbacks emit
event.BLURandevent.FOCUS, and the flags react to them exactly as they did to the window, silencing the sound effects, releasing held keys and undoing only a pause the engine applied. Turning the flags off would not do it: they cannot tell the window's events from the host's, so the host's pause would do nothing either.It can be called before or after the application is created.