Skip to content

KcdMp.onVisibility

Registers a function that is told when the interface is drawn or hidden.

fn({ visible, reason }) is called at once with the current state, then again at every change. visible is false while the interface is not drawn over the game, and reason says why: "loading" while a level loads, "menu" while a game menu is open, "game_screen" while one of the game’s own screens is up, "panic" after the player switched the interface off, "hidden" while it is turned off, and "" while it is drawn. A page that plays sound or animation can pause it meanwhile.

KcdMp.onVisibility(fn)
Parameter Type
fn (visibility: KcdMpVisibility) => void called with the state

() => void - a function that takes the handler off again

Whether the interface is drawn, and if not, why.

Field Type
visible boolean true while the interface is drawn over the game
reason "loading" | "menu" | "game_screen" | "panic" | "hidden" | "" why it is not drawn: "loading" (a level is loading), "menu" (a game menu is open), "game_screen" (one of the game’s own screens is up), "panic" (the player switched the interface off), "hidden" (it is turned off), and "" while it is drawn
KcdMp.onVisibility(({ visible }) => {
document.body.classList.toggle("paused", !visible);
});

KcdMp.feed.visibility.subscribe · KcdMp.focus · the Focus and visibility group of the index