Skip to content

Mirror mode, backdrop and view

In mirror mode the TV shows the phone’s camera video full screen, mirrored, and the game on top: the children see themselves among the stars. The video never reaches the game: the screen puts it under the game’s frame, and the game keeps receiving only bodies and movements, as always. A parent turns it on from the phone, and it works only while phone and TV are on the same home network.

A game takes part by declaring it in its manifest:

{ "...": "...", "backdrop": ["video"] }

Games that do not declare it never get the video: the children see themselves as their avatars.

The host tells the game what is behind it, 'video' or 'none', at the start and whenever it changes (the parent’s switch, the network, a pause of the video):

// Script tag
FabiPlay.on('start', ({ backdrop }) => setBackdrop(backdrop))
FabiPlay.on('backdrop', ({ backdrop }) => setBackdrop(backdrop))
// npm
const play = await connect()
setBackdrop(play.backdrop)
play.onBackdrop((backdrop, view) => setBackdrop(backdrop))

The video runs only while a game that supports it is running. On the home screen, at the end screen and between games it stops (the screen tells the phone idle), and the phone shows that it will start again with the next game: this is not an error. So a game always starts with whatever backdrop start says, and may see it change mid-game.

  • Paint no opaque background: no sky, no wallpaper, no full-screen fill. Clear the canvas (ctx.clearRect(…), or a transparent clear colour in WebGL with premultipliedAlpha as your engine expects) and make the page transparent too: html and body with background: transparent.
  • Do not set color-scheme on the page: a frame whose colour scheme differs from the TV’s is painted opaque by the browser.
  • Draw only what is on top: the things to catch, the effects, the score. Over a real room, light or dark, they need contrast: a dark outline or a soft dark shadow around shapes and text works on any background.
  • No avatars: the children are in the video.

Draw your background again, as before. Switch at once, mid-game, both ways.

Old TVs, a phone on another network, a parent who turns it off: most of the time the backdrop is 'none', and it can change at any moment. The game must be complete with its own background.

The video arrives a little late. In mirror mode Fabi Play holds the bodies and movements back by about the same amount (measured as it goes), so they arrive with the image they were read from. Do not add delays of your own.

That is in time. In place, what the game draws lines up with the children in the video only if it is drawn at toScreen(…) of their body points (below).

Drawing on the children: view and toScreen

Section titled “Drawing on the children: view and toScreen”

The video does not have the shape of the screen. A phone held upright gives a tall image, shown whole in the middle of a wide TV (blurred copies of it fill the sides); a phone held sideways gives an image that fills the screen, cropped at the top and bottom.

The host says where the whole camera image is, as view: { x, y, w, h } in fractions of the game’s viewport (they may go past 0–1 when the image is cropped). It does so with any backdrop, and the screen decides it:

  • with 'video', it is where the video is drawn (cropped to fill the screen, or shown whole);
  • with 'none', it is the whole camera image, shown whole at 92% of the screen’s height and standing on its bottom edge (a “virtual mirror”), so avatars and hands are where the children stand.

These rules are the screen’s and may change: just use view (or toScreen), never compute it yourself.

Automatic framing: the view zooms in on far children

Section titled “Automatic framing: the view zooms in on far children”

Children standing far from the phone are small in its image, so their avatars are small and their hands reach less of the screen. As a video call does, the screen frames them: it zooms the camera image in on the children (up to 1.8×, video included), so a far child’s avatar is about the size of a near one’s. The nearest child sets the zoom: no child is drawn bigger than the right size, so with a near and a far child together the far one stays smaller. Above every child there is room for their hands raised and their own avatar’s ears or hat, a little under the top edge. The image may then reach past every edge of the viewport.

The framing changes only when the game is still: as calibration ends, and at each pause and break (a grown-up’s pause, break('level'), a turn; not break('gameover')). The new view arrives in backdrop messages, one per screen frame for 1.5 seconds. On a break, break-done comes only once the view has settled; without an ad there is no break-start, so the game’s sound goes on and its avatars keep moving with the view (see Pause, breaks and audio). On a pause, the last view arrives before resume. Never during play. A child who joins or leaves is framed at the next pause or break.

A game drawn on exact spots of the live video, which must see the whole camera image, opts out in its manifest:

"framing": "fixed"

The default is "auto". With the TV remote the image is never zoomed (the puppet is no child in a camera).

Body points (player space, 0–1 of the camera image, already mirrored like the video) are on screen at (x + p.x·w, y + p.y·h). The SDK does it for you:

// Script tag: FabiPlay.toScreen and FabiPlay.view; npm: play.toScreen and play.view
FabiPlay.on('players', ({ players }) => {
for (const p of players) {
const wrist = { x: p.body[15 * 3], y: p.body[15 * 3 + 1] } // left wrist (index 15)
const s = FabiPlay.toScreen(wrist) // screen fractions: multiply by the canvas size
drawGlow(s.x * width, s.y * height)
}
})

Without a view (older hosts, or before start) toScreen returns the point unchanged, as if the camera image filled the screen.

Draw on the children at toScreen(…) of their body points, in every mode, and test what they touch there too: in the video that is the real hand, over your own background it is the hand of their avatar (drawn in the view, see Players and avatars). The hand pointers (hands, leftHand, rightHand) remain an option for things not drawn on the body (see Hands as pointers).

backdrop and view arrive in init and in a { ns: 'fabi-play', type: 'backdrop', backdrop, view } message. See Other engines.

The simulator’s «Mirror (webcam)» switch puts your webcam under the game and sends backdrop: 'video', to check that the background is transparent. See Testing with the simulator.