The start screen
appScenes gives a game its usual scenes in one call: the start screen (what the game is, a button for each scene), the game, the settings, a random map, the map editor and a server. It returns a plain list, so you add or remove scenes.
Quick start
const scenes = appScenes({
game,
maps,
onStart,
home: { buttons: [{ label: 'Campaign', scene: campaign.menu }], behind: livingScene, component: StartScreen },
extra: campaign.scenes,
scenes: { play: { name: 'Free play' } }
})
startApp({ target: '#game', game, scenes, start: sceneAsked(scenes, 'home') })The start screen gets a Campaign button first, a game playing behind it, and your own look; Play is renamed Free play; the campaign's scenes are added.
Common tasks
Rename a scene or give it a loading screen
appScenes({ game, scenes: { play: { name: 'Free play', label: 'Play now', loading: { text: 'Raising the banners…' } } } })id replaces a scene's id.
Add Exit for a desktop build
appScenes({ game, menu: { buttons: [exitButton(shell)] } })exitButton(shell) shows only where the shell can quit. See A desktop app.
Load the view and the editor only when needed
const game = createGame(rules).view(() => import('./view'))
const scenes = appScenes({
game,
editor: (scene) => import('@v12-engine/editor').then((editor) => editor.editorScene(scene)),
server: true
})The start screen then loads none of the looks, the client that draws them, or the renderer: an empty project's start screen loads 0.7 MB of script instead of 4.9 MB.
Make the random map's preview in a worker
// generate.worker.ts
import { serveMapGenerator } from '@v12-engine/engine'
import { game } from './game'
serveMapGenerator(game)
// main.ts
appScenes({ /* … */ generatorWorker: () => new Worker(new URL('./generate.worker.ts', import.meta.url), { type: 'module' }) })Fetch Play's code ahead
appScenes({ game, menu: { warm: ['play'] } })Reference
appScenes options
| Option | What |
|---|---|
game | from createGame: its rules, maps and start |
maps, onStart | other maps and start than the game's |
home | the start screen: buttons, after, behind, component |
menu | the start screen's menu: buttons, warm |
scenes | per scene: name, label, loading, id |
extra | scenes of your own |
editor | the editor scene, or a function returning a promise of it |
server | true, or { rooms: true } for rooms |
saves | {}: the game can be saved from its pause menu |
generatorWorker | makes the random map's worker |
Every scene but the start screen is lazy. Pushing to the list afterwards (scenes.push, home.buttons.unshift) still works but is the old way, and ids is deprecated.
A project from npm create @v12-engine is the example: its start screen (home, in src/main.ts) has Play, which opens play, whose Home button goes back.