Menus, settings and motion
Esc opens the pause menu: Resume, Settings, Keys, Save and load, Give up, Restart, Leave. You add lines of your own, add or change settings, and control how much menus animate.
Quick start
hud: {
menu: {
entries: [{ id: 'objectives', label: 'Objectives', run: (client) => showObjectives(client) }],
standard: true, // keep the client's lines
onEscape: true // false: Esc is your game's, and you open the menu in code
},
settings: {
add: [{ id: 'td.confirmSell', label: 'Ask before selling a tower', kind: 'toggle', default: true, section: 'game' }],
hide: ['blood'],
change: { scrollSpeed: { default: 60 } }
}
}The menu gets an Objectives line, the settings a toggle of yours, no blood option and a faster default scroll.
Common tasks
Read or set a setting
client.settings.get('td.confirmSell') // a signal
client.settings.set('hudSize', 1.2) // clamped, applied, kept, told
client.settings.onChange((id, value) => { /* … */ })
client.settings.reset()Open or close the menu from code
client.menu has show, close, go, entries(). A game played in the page pauses while the menu is open; one played with others goes on.
Take a picture of the view
client.capture() gives what the camera sees, without the HUD, as a data URL with its size ({ url, width, height }), at the screen's own size.
Animate a screen of your own
import { Presence, ScreenTransition, Stagger } from '@v12-engine/client/kit'
<Presence present={open()} onExitComplete={() => console.log('gone')}><Panel>...</Panel></Presence>
<Stagger class='grid gap-2' step={60}>{buttons}</Stagger>
<ScreenTransition screen={page()}>{(page) => (page === 'main' ? <Main /> : <Options />)}</ScreenTransition>In plain HTML, use the classes (classes.motion): vg-presence and vg-slide animate by data-state (open, closed; remove the element on animationend), vg-stagger brings children in one after another, vg-leaves slides off as its scene goes.
Turn motion down
--vg-motion is how much the interface moves: 1, 0 for none, 2 for twice as slow. The player's motion setting and the system's prefers-reduced-motion go over it. At 0 nothing animates and every scene change is a cut.
Make teams readable for colour-blind players
settings: { change: { teamColors: { default: 'distinct' }, sideMarks: { default: true } } }
client.teamColors = 'sides' // or (player, index) => rgb
client.sideMarks = trueKeep the pointer in the game
settings: { change: { keepPointer: { default: 'always' } } } // 'never', 'fullscreen' (default), 'always'The browser grants pointer lock only on a press, so the first press in the game takes it. The pause menu gives it back. Esc, which releases it, can't be stopped by a page: losing the lock opens the pause menu unless you said menu.onEscape: false.
React when the tab is hidden
onHidden: (hidden, client) => { if (hidden) client.menu.show() }A game in the page holds while hidden and goes on when seen. A server game goes on; the client catches up when seen again.
Reference
The pause menu
Esc opens it only once there is nothing else to put away: an order being aimed, a building being placed, a debug tool, the shop, the keys list, the layout mode, then the selection (unless locked, or selection.clickEmpty is 'clear'). In the menu, Esc backs out of a page, then closes. The top bar's menuButton opens it too. In a game played in the page, the menu holds the game and freezes its picture (client.freeze): units stop mid-swing, effects, rain and the sky stand still, and all of it goes on from where it was as the menu closes. On a server the game goes on, so nothing is held or frozen. The parts are PauseMenuScreen and SettingsList (@v12-engine/client/hud).
A setting
{ id, label, kind: 'toggle' | 'number' | 'choice' | 'text', default, apply(client, value) }, with min, max, step, show for numbers, options for a choice, a hint, a section, and shown: (client) => … for where it appears. hidden: true keeps it off the screen (and out of a reset) but still readable. Settings are kept per player across games, under the page's storage prefix.
The client's settings
| Setting | What |
|---|---|
| edge scrolling, its width | scroll at the screen's edge |
keepPointer | pointer lock: never, fullscreen, always |
| scroll speed | camera scroll speed |
zoom | how far the wheel zooms out, a share of the game's limit |
| double-click range | what a double-click adds |
| health bars always shown | |
blood | |
teamColors | game, distinct (Okabe and Ito's set), sides (you blue, allies sky blue, enemies orange) |
sideMarks | a circle, square or triangle under units by side, on the minimap too |
| quality and its knobs | see Graphics quality |
maxFps | frames a second at most |
gameSpeed | 0.5× to 3×, only where the player holds the pace (client.pace) |
| volume | all, music, effects, voices, ambience, interface |
hudSize | the HUD's size |
| hints | the rules' world.hint messages |
screenShake | off: the view never shakes (client.camera.shakes = false) |
motion | system, less, full |
subtitles, textSpeed | dialog as subtitles; slower, normal, faster, instant (client.ui.setDialogPrefs, DialogPrefs) |
language | see Languages |
Motion components (@v12-engine/client/kit)
| Component | What |
|---|---|
Presence | there while present, kept until its exit animation ends (onExitComplete); motion: 'slide' |
Stagger | children come in step ms apart (45; the eighth on together) |
ScreenTransition | one screen over to the next by key; motion: slide (default), fade, cut |
The Tailwind animations: animate-hud-in, animate-hud-out, animate-pop-in, animate-pop-out, animate-fade-out, animate-slide-in, animate-slide-out, animate-scene-in, animate-scene-slide, each --vg-motion long. Scene-to-scene transitions are in Scenes.
Pointer lock in detail
While locked, the client keeps the pointer's position, draws it ([data-vg-pointer], with the CSS cursor of what is under it) and forwards every pointer event to what is under it, so picking, box select, edge scroll, the minimap and your HTML work unchanged. Two things it can't give:
- CSS
:hoverstays where the browser's pointer is. What is under the kept pointer hasdata-vg-hover; write:is(:hover, [data-vg-hover]). - The browser refuses
setPointerCapturewhile locked: usecapturePointer(element, pointerId).
For a pointer of your own, hide the client's ([data-vg-pointer] { display: none }) and draw yours at client.pointerLock.at() each frame, with HOVER to know what is under it.
| Declared | In code |
|---|---|
the setting keepPointer | client.pointerLock: keep, locked(), lock(), release(), at(), onChange, cursor |
GameView.input.lockKeys | client.keyboardLock |
GameView.onHidden(hidden, client) | client.hidden, client.onHidden(listener) |
A host run in a hidden tab is slowed by the browser to a step a second; the others wait for it.