Skip to content

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 ​

ts
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 ​

ts
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 ​

tsx
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 ​

ts
settings: { change: { teamColors: { default: 'distinct' }, sideMarks: { default: true } } }
client.teamColors = 'sides' // or (player, index) => rgb
client.sideMarks = true

Keep the pointer in the game ​

ts
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 ​

ts
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 ​

SettingWhat
edge scrolling, its widthscroll at the screen's edge
keepPointerpointer lock: never, fullscreen, always
scroll speedcamera scroll speed
zoomhow far the wheel zooms out, a share of the game's limit
double-click rangewhat a double-click adds
health bars always shown
blood
teamColorsgame, distinct (Okabe and Ito's set), sides (you blue, allies sky blue, enemies orange)
sideMarksa circle, square or triangle under units by side, on the minimap too
quality and its knobssee Graphics quality
maxFpsframes a second at most
gameSpeed0.5× to 3×, only where the player holds the pace (client.pace)
volumeall, music, effects, voices, ambience, interface
hudSizethe HUD's size
hintsthe rules' world.hint messages
screenShakeoff: the view never shakes (client.camera.shakes = false)
motionsystem, less, full
subtitles, textSpeeddialog as subtitles; slower, normal, faster, instant (client.ui.setDialogPrefs, DialogPrefs)
languagesee Languages

Motion components (@v12-engine/client/kit) ​

ComponentWhat
Presencethere while present, kept until its exit animation ends (onExitComplete); motion: 'slide'
Staggerchildren come in step ms apart (45; the eighth on together)
ScreenTransitionone 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 :hover stays where the browser's pointer is. What is under the kept pointer has data-vg-hover; write :is(:hover, [data-vg-hover]).
  • The browser refuses setPointerCapture while locked: use capturePointer(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.

DeclaredIn code
the setting keepPointerclient.pointerLock: keep, locked(), lock(), release(), at(), onChange, cursor
GameView.input.lockKeysclient.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.