Skip to content

Menus ​

A menu scene is a title and buttons, each opening a scene or running something. It is plain data the app draws, optionally with a game or a cinematic playing behind it and music of its own.

Quick start ​

ts
const home = menuScene({
	id: 'home',
	name: 'Home',
	title: 'My game',
	buttons: [
		{ label: 'Play', scene: play },
		{ label: 'Credits', run: (goTo) => goTo(credits) }
	],
	behind: cinematicScene({ id: 'flyover', game, map: valleyMap, cinematic: 'menu-flyover', skippable: false, play: { letterbox: false } }),
	music: 'theme'
})

A title over a fly-over of your map, two buttons, and the menu's music.

Common tasks ​

Show a button only sometimes ​

ts
buttons: [{ label: 'Exit', run: () => shell.quit(), shown: () => shell.canQuit() }]

exitButton(shell) is that Exit button, ready-made.

Pass arguments to the scene a button opens ​

ts
buttons: [{ label: 'Mission one', scene: mission, args: { mission: 'first' } }]

Draw the menu your own way ​

ts
menuScene({ id: 'home', name: 'Home', title: 'My game', buttons, component: (props) => <MenuScreen {...props} /> }) // wrap or replace
menuScene({ id: 'home', name: 'Home', title: 'My game', buttons, mount: (element, { scene, goTo }) => drawMenu(element, scene, goTo) })

A menu with its own mount asks button.shown?.() as it draws its buttons.

Give the game behind a loading screen ​

ts
behind: { scene: flyover, loading: { text: 'Loading…' } }

By default what plays behind shows no loading screen: it stays hidden until on, then eases in over 400 ms times --vg-motion.

Play a game in an element of your own ​

ts
playScene(scene, element, context, { onLoaded, loading, keepsMusic })

Reference ​

FieldWhat
id, name
titlethe menu's title
buttonsMenuChoices: label, scene (with args) or run(goTo), shown
backgroundbehind the buttons
behinda game scene played behind (a scene, or { scene, loading }: LoadingLook)
musicits music, handed from scene to scene through the app's mixer
warmscenes to fetch ahead (MenuDef.warm)
transitionhow it comes in
component, mountyour own drawing (MenuScreen to wrap)

Going between menus with the same behind hands it over still playing. The menus' motion (title in, buttons one after another, sliding off as the scene goes) comes from the kit: see Menus, settings and motion.

The example's Title scene (apps/example/src/scenes/title.ts) is two lines on a black stage, then its menu over a slow fly-over. See A cinematic of its own.