Mirror mode
In mirror mode the TV shows the children’s camera video behind the game: they see themselves among the stars. The engine does most of the work.
What the engine does
Section titled “What the engine does”When engine.backdrop is 'video':
- the stage is cleared to transparent, and the
backgroundoption ofcreateEngineis not painted; - the page’s
htmlandbodygetbackground: transparent(and get their own background back afterwards). The engine leavescolor-schemealone, as it must; engine.avatars()draws nothing: the children are in the video;engine.hands()are on the real hands, from the frame’s own bodies.
When it goes back to 'none', all of that switches back, at once, mid-game.
What your game does
Section titled “What your game does”Declare it. Only games whose manifest says "backdrop": ["video"] ever get the video (see
The manifest).
Hide your opaque background. If your background is one colour, pass it as background to createEngine and
there is nothing to do. If it is an image or a scene, hide it while the video is behind:
const sky = stage.add(engine.sprite('sky', { width: stage.width, height: stage.height }))const showSky = () => (sky.visible = engine.backdrop !== 'video')showSky() // onBackdrop tells only of changes: start from the current backdropengine.onBackdrop(showSky)engine.onBackdrop((backdrop, view) => …) is called when the backdrop or the view changes, not at the start:
read engine.backdrop once when you set up. It returns a function that stops listening. engine.view is the current
view.
Keep what is on top readable. Over a real room, light or dark, things need contrast: give shapes an outline
(stroke, lw) and texts an outline or a shadow. Fabi Play’s Star Shower bakes its stars in two looks, a glow
over the sky and an outline with a dark halo over the video, and switches with the backdrop:
import type { Backdrop, ShapeSpec } from '@fabiplay/engine'
const look = (b: Backdrop): ShapeSpec => b === 'video' ? { type: 'star', r: 40, fill: '#FBD46A', stroke: '#1F1813', lw: 4 } : { type: 'star', r: 40, fill: '#FBD46A', shadow: { color: '#FBD46A', blur: 12 } }
const star = stage.add(engine.shape(look(engine.backdrop), { x: 640, y: 100 }))engine.onBackdrop((b) => (star.spec = look(b))) // bakes it again, once per changeNever assume the video is there. Most of the time the backdrop is 'none', and it can change at any moment: the
game must be complete with its own background.
Testing it
Section titled “Testing it”In the simulator, «Mirror (webcam)» puts your webcam under the game and sends backdrop: 'video'. Check that the
background goes, that what is left reads well over your room, and that it comes back when you switch it off. See
Testing with the simulator.