Your repo
Inside PushPlay
What a game can read from PushPlay while it runs (the window.pushplay object), how to pause, quit and save, and the optional runtime files that do it for you.
The window.pushplay object
In the launcher, the app and the check, a web game gets a window.pushplay object before its scripts run. Outside PushPlay it is undefined, so always write window.pushplay?.….
| Member | What it is |
|---|---|
version |
The launcher’s or app’s version |
gamingMode |
The launcher is in its gaming mode: start out showing controller prompts |
inputMode |
The launcher’s current input mode |
device |
{ kind, performance }: what the game runs on. kind is 'tv', 'tablet', 'phone', 'handheld' or 'desktop'; performance is 'low' or 'normal' |
quit() |
Close the game and go back to the Library |
restart() |
Restart the game |
onPause(cb), onResume(cb) |
Called when PushPlay pauses and resumes the game. Each returns a function that stops listening |
phonesWaiting |
How many phones were connected as PushPlay’s remote when the game started |
phoneRoom({ code } | null) |
Tell PushPlay your phone room’s code when it opens, and null when it closes, so the phones in use as its remote can follow the player in |
The window also gets the events pushplay:pause and pushplay:resume.
window.addEventListener('pushplay:pause', () => pauseGame())
if (window.pushplay?.quit) pauseMenu.add('Quit to library', () => window.pushplay.quit())
Pausing
PushPlay pauses the game when its own menu opens (F10, Start + Select, a held Esc, the ≡ button, or Back on a TV remote), and a phone pauses it when the app is hidden. When that happens: stop the game, save, and wait. Never resume by yourself; the player resumes from your pause menu or PushPlay’s.
A good pause menu has, in order: Resume, Restart, Settings, and Quit to title, plus Quit to library when window.pushplay?.quit exists. With a mouse or touch, give it an on-screen pause button of at least 56×56 px.
Quitting
- A web game can always be left through PushPlay’s menu. Add Quit to library to your own pause menu too.
- A native game needs its own quit, reachable with a controller. On Linux, PushPlay also closes a native game when Start + Select is held for three seconds; on Windows and Mac it doesn’t.
Slow devices
A TV box has a phone’s graphics chip behind a 1080p or 4K screen. device.performance is 'low' on every TV, and on any device where this game was measured running slowly; everywhere else, and when device is missing, treat it as 'normal'.
const low = window.pushplay?.device?.performance === 'low'
When it’s low:
- Render fewer pixels. One device pixel per CSS pixel, instead of following
devicePixelRatio. - Start on your lowest graphics setting. Fewer shadows and particles, no post-processing, 30 frames a second if 60 won’t hold.
- The player’s choice wins. If the player picks a graphics setting, save it and keep it, whatever the hint says later.
Choose quality by performance, never by kind: a desktop can be slow and a tablet fast. Use kind for what the screen is.
Saving
Keep saves in localStorage under keys that start with the game’s id, such as star-courier-save-v1. The check notes (⚠) keys without the prefix. Saves follow the id across updates and repo moves, and each channel a player adds has saves of its own.
Tell the check where you are
Set window.__game so the check (and the TV pass) can see which screen the game is on:
window.__game = { state, TUNING }
// state.screen is one of 'title', 'playing', 'paused', 'gameover', 'settings', 'lobby'
Without it the check can’t confirm that Start pauses or that a TV remote starts the game. The runtime files set it for you.
Your own release and PushPlay’s
Inside PushPlay a game must work offline and without dialogs. To keep analytics, ads, a login or an online leaderboard in your normal release, tell the two apart:
if (!window.pushplay) {
loadAnalytics()
showNewsletterPrompt()
}
- At build time,
PUSHPLAY_BUILD=1is set when the workflow runs your build, so a bundler can leave a module out. - A native game gets the environment variable
PUSHPLAY=1when PushPlay starts it.
The runtime files
For a JavaScript game started from nothing, the kit has a small set of plain ES modules that do what every PushPlay game needs. They’re optional, and the starter template and new-game use them. A game on them is held to more by the check (each listed input alone, pausing, scaling), and in return gets Quit to library, auto-pause and the hooks above without writing them.
| File | What it does |
|---|---|
input.js |
One view of controller, keyboard, mouse and touch, with button labels for the device in use |
menu.js |
Menus that work with every input; adds Quit to library inside PushPlay |
fit.js |
Scales a 1280×800 (or phone) space to any window, with no bars; safe areas; fewer pixels on a slow device |
save.js, settings.js |
Versioned saves under the game’s id; a Settings screen with volumes, reduced shake and flash, text size and graphics |
audio.js |
Master, music and SFX buses; muted on pause |
ui.js, fonts.js |
The standard look of a game’s title, pause and results screens |
prompts.js, touch.js |
Button-prompt icons for the device in use; an on-screen stick and buttons |
net.js, lobby.js |
Online games on PushPlay’s relay |
party.js, controller.js, phone-pads.js, motion.js and others |
Party games, phones as controllers and motion (Party, phones and motion) |
Each starts with the header pushplay runtime vN. Don’t edit them: update-runtime replaces them with the current versions and leaves alone any file of the same name you wrote yourself.
npx github:Visual-Zone-Development/pushplay-kit update-runtime
Edit this page on GitHub · Something missing or wrong? Tell us.