Skip to content

Events and bodies

FabiPlay.on(event, listener) (the script tag, or easy(connect()) with npm) listens for an event by name and returns a function that stops listening. Everything can be called before Fabi Play starts the game: it waits for it.

Event When it arrives The listener gets
jump, land Jump and landing { player }
squat, stand Squat and standing back up { player }
clap The hands meet { player }
freeze, move Still as a statue, then moving again { player }
lane-left, lane-center, lane-right A sideways step into a lane (the child’s own left, as in a mirror) { player }
shape The body shape changes { player, shape }: 'arms-up', 'arms-wide', 'arms-v', 'star', 'arms-down', or null
hands Every frame, about 30 a second, once per player { player, left, right }: hand pointers, { x, y } from 0 to 1, or null
players Every frame { players }: every player with body, hands, shape, lane and avatar
start The game starts (late listeners still get it) { ageRange, players, locale, mode, backdrop, view, device }
backdrop The video behind the game went on ('video') or off ('none'), or the camera image moved { backdrop, view }
pause, resume Pause and resume from the phone {}
break-start, break-end Fabi Play shows an ad, and it is over {}, then { shown }

What start says:

Field Values
ageRange '3-5', '6-8' or '9-12': simpler rules for the little ones, scores and challenges for the older ones
players The player ids, [1, 2, …]
locale 'it' or 'en': the language to show text in
mode 'tv' (on a TV or Chromecast, children standing back) or 'solo' (a tablet in front of one child)
backdrop 'video' or 'none': see Mirror mode
view Where the camera image is on the screen, or null: see Mirror mode
device What the TV’s screen knows about the device, or null: see The device hint

play.on(event, listener) listens for the host’s messages as they are. The fields of start are on play itself as soon as connect() resolves (play.ageRange, play.players, play.locale, play.mode, play.muted, play.backdrop, play.view, play.device).

Event The listener gets
frame { t, players }: every camera frame, about 30 a second; t is when it was taken (ms)
gesture { t, player, gesture }: gesture is one of jump, land, squat, stand, clap, freeze, move, lane-left, lane-center, lane-right
pause, resume The grown-up paused or resumed from the phone
break-start, break-done Fabi Play shows an ad; break-done has { shown }
backdrop { backdrop, view }; or use play.onBackdrop((backdrop, view) => …)

Each frame (players with the script tag, frame with npm) carries one PlayerFrame per player seen:

Field What it is
id The player, from 1
body The 33 body points (below)
leftHand, rightHand The hand pointers, { x, y } from 0 to 1 of the screen, or null when the camera doesn’t see that wrist
shape The pose held right now ('arms-up', 'arms-wide', 'arms-v', 'star', 'arms-down'), or null
lane Which lane the child stands in: -1 left, 0 centre, 1 right
avatar The avatar the child picked on the phone (see Players and avatars)

The whole body is there, every frame. body holds the 33 MediaPipe Pose landmarks as the phone read them, flat: [x0, y0, visibility0, x1, y1, visibility1, …], so point i is at body[i * 3], body[i * 3 + 1] with its visibility at body[i * 3 + 2].

  • x and y go from 0 to 1 of the camera image, y downwards.
  • Visibility goes from 0 to 1: trust a point from about 0.5.
  • It is in player space: mirrored like a mirror, whatever camera took it, so a child moving to their left moves left on screen. Left is the child’s left, as in a mirror.
Point Index Point Index
Nose 0 Left / right hip 23 / 24
Left / right shoulder 11 / 12 Left / right knee 25 / 26
Left / right elbow 13 / 14 Left / right ankle 27 / 28
Left / right wrist 15 / 16

The other indices are MediaPipe Pose’s (eyes, ears, mouth, hands, heels, feet).

With the body a game can draw its own character or skeleton. To put something where the child stands on screen, map the body point with toScreen (see Mirror mode); or draw it wherever you like. In mirror mode the body is held back by the host exactly like the rest of the frame, so it is in step with the video.

leftHand and rightHand (and the hands event) are not the wrists where they are on screen: they are stretched around each child’s shoulders and clamped to the screen, so a child reaches every corner without walking. That makes them good for things that are not drawn on the body (a menu cursor, aiming), or for a game that draws no body at all.

To draw on the children, or to test what their hands touch, use the body’s wrists through toScreen instead: in the video that is the real hand, over your own background it is the hand of their avatar. See Mirror mode and Players and avatars.

The first time the children are seen they are numbered left to right, as they stood in calibration (player 1 on the left). From then on each id stays with its child: two children who swap places keep their ids, avatars, names and scores, and a child who steps out of the frame and comes back gets their id back.

  • A player not seen in a frame is missing from players for that frame. Don’t end their game for it.
  • A person beyond the number of players (a grown-up walking by) is never sent to the game.

These two are for engines. A game on the Fabi Play engine gets both handled by the engine and can skip this section.

play.device (FabiPlay.device with the script tag, and device in the start event) is what the TV’s screen knows about the device the game runs on, or null when it says nothing (a plain browser, an older host):

{ tier?: 'high' | 'medium' | 'low', hz?: number }
  • tier: a starting quality tier, the TV platform’s default (most TVs 'medium'), or 'low' where the screen’s own drawing fell back to Canvas 2D;
  • hz: the display’s refresh rate (50, 60, …), measured by the screen.

Each game lives on its own site, so what one game measured about the device is not seen by the next. The screen knows it once for all of them: an engine can pick its quality from the hint instead of measuring the device again. It is a hint: keep lowering the quality if frames are slow. The Fabi Play engine starts from it by itself (see How the tier is chosen).

FabiPlay.device is null until the game starts: read it in start.

Reporting how the game draws: play.reportStats

Section titled “Reporting how the game draws: play.reportStats”
play.reportStats({ fps: 58, renderer: 'webgl2', tier: 'medium' }) // about once a second

play.reportStats({ fps?, renderer?, tier? }) (FabiPlay.reportStats with the script tag) says how the game draws now: its frame rate, its renderer (a short lowercase name such as 'webgl2', 'canvas2d' or your engine’s own, up to 16 characters) and its tier. It is for debugging only: the SDK passes the last values on to a debug host that asked for them, the simulator, which shows them in its status line. On a TV it sends nothing. The Fabi Play engine calls it by itself once a second.

Arms crossed in an X, held for 1.5 seconds, belong to Fabi Play: arms crossed in front of the chest, or a big X above the head (arms up, the forearms crossed over it). Children are no longer told about it, but it works. During a game the X pauses it (a ring fills around the child on the TV); on the game list it asks whether to close Fabi Play. The X only ever opens a choice: the children answer it by stretching one arm out sideways towards a button (the buttons are on the screen’s left and right edges), never with the X. Do not use either X as a move in your game: the child would pause it. Crossed arms are never a shape. Arms up crossing over the head are not “arms up” for your game either: an X’s first frame has no shape, and from its second frame in a row the child’s arms are hidden from it (below).

Nobody in the picture for 3 seconds pauses the game. When the bodies come from a camera and no child has been seen for 3 seconds (they walked off, or out of the frame), Fabi Play pauses the game as the X does: you get pause, then resume when they choose «Continua». Not with the TV remote.

While a child makes the X (from its second frame in a row), the game gets nothing from that child’s arms:

  • hands and the player’s leftHand / rightHand are null, and their shape is null;
  • elbows, wrists and hand points have visibility 0 in the body;
  • none of their movement events arrive (no clap, jump or the like).

The other children play on as usual, and everything comes back when the child lets go. A clap may still arrive as the hands pass each other on the way into the X.

Menus outside your game use the arms. In the pause, at the end and in the exit popup, an arm stretched out towards the left or right button presses it; on the game list an arm out moves the carousel and both hands up play. Your game does not draw or handle these menus; it just gets pause and resume.