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
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
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
buttons: [{ label: 'Mission one', scene: mission, args: { mission: 'first' } }]Draw the menu your own way
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
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
playScene(scene, element, context, { onLoaded, loading, keepsMusic })Reference
menuScene fields (MenuScene)
| Field | What |
|---|---|
id, name | |
title | the menu's title |
buttons | MenuChoices: label, scene (with args) or run(goTo), shown |
background | behind the buttons |
behind | a game scene played behind (a scene, or { scene, loading }: LoadingLook) |
music | its music, handed from scene to scene through the app's mixer |
warm | scenes to fetch ahead (MenuDef.warm) |
transition | how it comes in |
component, mount | your 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.