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.
Syntax
Section titled “Syntax”KcdMp.onVisibility(fn)| Parameter | Type | |
|---|---|---|
fn |
(visibility: KcdMpVisibility) => void |
called with the state |
Returns
Section titled “Returns”() => void - a function that takes the handler off again
KcdMpVisibility
Section titled “KcdMpVisibility”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 |
Example
Section titled “Example”KcdMp.onVisibility(({ visible }) => { document.body.classList.toggle("paused", !visible);});See also
Section titled “See also”KcdMp.feed.visibility.subscribe · KcdMp.focus · the Focus and visibility group of the index
