Easy
The simple API: window.FabiPlay from the script tag (fabi-play.js), or easy(connect()) with the npm package. Everything can be called before the screen starts the game: it waits for it.
Example
Section titled “Example”FabiPlay.on('jump', ({ player }) => hop(player))FabiPlay.on('hands', ({ player, aim }) => aim.right && touch(player, aim.right))await FabiPlay.break('level')FabiPlay.end(120)Extended by
Section titled “Extended by”Properties
Section titled “Properties”players
Section titled “players”
readonlyplayers: readonlynumber[]
The players playing now (frozen; see Play.players); empty before start.
readonlyturns: readonlynumber[]
Every child in turn order (frozen; see Play.turns); empty before start.
readonlyinput:GameInput
How this session is played (see Play.input); ‘body’ before start.
hasPointer
Section titled “hasPointer”
readonlyhasPointer:boolean
With input ‘remote’, whether the remote also points (Play.pointer: a Magic Remote, or the arrows as a cursor with “remoteCursor”: true; either way plain pointer and mouse events). pointer() is the hand adapter. False before start.
canSavePicture
Section titled “canSavePicture”
readonlycanSavePicture:boolean
Whether savePicture can reach a phone now (see Play.canSavePicture); false before start.
readonlymuted:boolean
The screen’s sound is off (see StartInfo.muted); false before start.
orientation
Section titled “orientation”
readonlyorientation:Orientation
The screen’s orientation at the start (see Play.orientation); ‘landscape’ before start.
safeArea
Section titled “safeArea”
readonlysafeArea:Readonly<SafeArea>
What a phone’s notch and home bar cover, fractions of the viewport (see Play.safeArea); zeros before start.
readonlyview:BackdropView|null
Where the camera image is, with any backdrop; null if the host didn’t say, and before start.
device
Section titled “device”
readonlydevice:DeviceHint|null
What the screen knows about the device (see Play.device); null if it said nothing, and before start.
drawAvatar
Section titled “drawAvatar”drawAvatar:
DrawAvatar
Draws a player’s avatar posed like them, smoothed per player: drawAvatar(ctx, players[i]). Optional: player (a player id, or an avatar id), box (where player space 0–1 lands on the canvas; default the view, where the child stands, else the whole canvas), { alpha, smooth }. Draw avatars only when backdrop is not ‘video’. Returns the smoothed body it drew (or null): put the hands on it, so they stay in the avatar’s hands.
smoothedBody
Section titled “smoothedBody”smoothedBody:
SmoothedBody
A player’s body smoothed as drawAvatar draws it (from a frame: smooths it, shared with drawAvatar; from a player id: the last one, or null). Use it for hit-tests and glows in avatar mode, so they follow the avatar’s hands.
Methods
Section titled “Methods”on<
K>(event,listener): () =>void
Listens to an event: a gesture by its name (‘jump’, ‘clap’, ‘lane-left’, …), ‘start’, ‘hands’, ‘shape’, ‘players’, ‘pause’, ‘resume’, ‘break-start’, ‘break-end’, ‘backdrop’, ‘turn’, ‘capabilities’ (see EasyEvents). Returns a function that stops listening.
Type Parameters
Section titled “Type Parameters”K extends "players" | "backdrop" | Gesture | "pause" | "resume" | "break-start" | "turn" | "capabilities" | "hands" | "start" | "shape" | "break-end"
Parameters
Section titled “Parameters”K
listener
Section titled “listener”(data) => void
Returns
Section titled “Returns”() => void
Example
Section titled “Example”const off = FabiPlay.on('clap', ({ player }) => fire(player))ready()
Section titled “ready()”ready():
void
Say the game is loaded; done for you on page load unless the script tag says data-ready=“manual”.
Returns
Section titled “Returns”void
score()
Section titled “score()”score(
score,player?):void
The score so far, for the screen to show; player 1 unless said (with input ‘remote’, the child playing now).
Parameters
Section titled “Parameters”number
player?
Section titled “player?”number
Returns
Section titled “Returns”void
break()
Section titled “break()”break(
reason?):Promise<boolean>
The game stopped by itself (‘level’ or ‘gameover’, never its pause menu): Fabi Play may show an ad. Resolves when it can go on.
Parameters
Section titled “Parameters”reason?
Section titled “reason?”Returns
Section titled “Returns”Promise<boolean>
end(
score):void
The end: a score (player 1’s; with input ‘remote’, the child playing now’s, and for each child who played before them in turns their last score() or 0), or one per player. Stars from 0 to 3, 2 if not given.
Parameters
Section titled “Parameters”number | object[]
Returns
Section titled “Returns”void
keys()
Section titled “keys()”keys(
map?,options?):void
Presses keys for movements, for a game played with the keyboard (see keyboard()): by default Space while in the air, ArrowDown while crouched, arrows for side steps, Enter on a clap. The script tag’s data-keys does the same.
Parameters
Section titled “Parameters”Partial<Record<Action, string>>
options?
Section titled “options?”Omit<KeyboardOptions, "target">
Returns
Section titled “Returns”void
Example
Section titled “Example”FabiPlay.keys({ jump: 'Space', left: 'ArrowLeft', right: 'ArrowRight' })pointer()
Section titled “pointer()”pointer(
options?):void
The child’s hand as the mouse, for a game played with the pointer (see pointer()): it moves the pointer and clicks by staying still on a spot. The script tag’s data-pointer does the same.
Parameters
Section titled “Parameters”options?
Section titled “options?”Omit<PointerOptions, "target">
Returns
Section titled “Returns”void
savePicture()
Section titled “savePicture()”savePicture(
source,opts?):Promise<PictureResult>
Saves a picture on the family’s phone: a canvas (scaled to 1920 px at most, JPEG) or a data URL (JPEG or PNG), with an optional title. Resolves ‘sent’, ‘unavailable’, ‘too-big’ or ‘error’ (see Play.savePicture); called before start, it waits for it. Only TV → phone over their direct link, never to a server.
Parameters
Section titled “Parameters”source
Section titled “source”title?
Section titled “title?”string
Returns
Section titled “Returns”Promise<PictureResult>
Example
Section titled “Example”if (FabiPlay.canSavePicture) FabiPlay.savePicture(canvas, { title: 'Il nostro muro' })reportStats()
Section titled “reportStats()”reportStats(
stats):void
For engines, debug only: how the game draws now (see Play.reportStats). Dropped before start.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
toScreen()
Section titled “toScreen()”toScreen(
p):Point
A body point (player space, 0–1, as in players[i].body) on the screen, in fractions: where the child is, in the video or on their avatar. Draw hands and effects at toScreen(wrist), in every mode. Unchanged without a view.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”aim(
player,side):Point|null
Where a player’s hand aims on the screen, in fractions (0–1), by player id or from a frame: use it for what the hand touches; toScreen(wrist) only to draw on the body. On a TV or a tablet the hand on the body (the avatar’s, or the real one over the video); on a phone held upright the wrist stretched to the whole screen, so raised hands reach the top. See Play.aim. null when not seen, and before start.
Parameters
Section titled “Parameters”player
Section titled “player”number | PlayerFrame
Returns
Section titled “Returns”Point | null
avatarOf()
Section titled “avatarOf()”avatarOf(
player):string
The avatar id a player picked on the phone, by player id or from a frame (players[i]); the slot’s default (fox, lion, dragon, unicorn: the 6–8 band’s, as no age is known here) until the first frame says otherwise.
Parameters
Section titled “Parameters”player
Section titled “player”number | PlayerFrame
Returns
Section titled “Returns”string