FabiPlayGlobal
window.FabiPlay, as fabi-play.js sets it: the simple API (Easy), plus the avatars’ rig it carries for the engine.
For a script-tag game written in TypeScript: declare const FabiPlay: FabiPlayGlobal (or reference
dist/fabi-play.d.ts, which declares it).
Extends
Section titled “Extends”Properties
Section titled “Properties”players
Section titled “players”
readonlyplayers: readonlynumber[]
The players playing now (frozen; see Play.players); empty before start.
Inherited from
Section titled “Inherited from”
readonlyturns: readonlynumber[]
Every child in turn order (frozen; see Play.turns); empty before start.
Inherited from
Section titled “Inherited from”
readonlyinput:GameInput
How this session is played (see Play.input); ‘body’ before start.
Inherited from
Section titled “Inherited from”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.
Inherited from
Section titled “Inherited from”canSavePicture
Section titled “canSavePicture”
readonlycanSavePicture:boolean
Whether savePicture can reach a phone now (see Play.canSavePicture); false before start.
Inherited from
Section titled “Inherited from”
readonlymuted:boolean
The screen’s sound is off (see StartInfo.muted); false before start.
Inherited from
Section titled “Inherited from”orientation
Section titled “orientation”
readonlyorientation:Orientation
The screen’s orientation at the start (see Play.orientation); ‘landscape’ before start.
Inherited from
Section titled “Inherited from”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.
Inherited from
Section titled “Inherited from”
readonlyview:BackdropView|null
Where the camera image is, with any backdrop; null if the host didn’t say, and before start.
Inherited from
Section titled “Inherited from”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.
Inherited from
Section titled “Inherited from”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.
Inherited from
Section titled “Inherited from”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.
Inherited from
Section titled “Inherited from”avatars
Section titled “avatars”
readonlyavatars:Readonly<Record<string,unknown>>
The avatars’ rig and data fabi-play.js carries (for drawAvatar), handed over to fabi-play-engine.lite.js or a
bundler alias so the engine doesn’t ship them twice. Not a game API: draw avatars with drawAvatar. Typed in
@fabiplay/sdk/avatars.
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))Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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>
Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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' })Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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' })Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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”Inherited from
Section titled “Inherited from”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
Inherited from
Section titled “Inherited from”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