Skip to content

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).

readonly players: readonly number[]

The players playing now (frozen; see Play.players); empty before start.

Easy.players


readonly turns: readonly number[]

Every child in turn order (frozen; see Play.turns); empty before start.

Easy.turns


readonly input: GameInput

How this session is played (see Play.input); ‘body’ before start.

Easy.input


readonly hasPointer: 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.

Easy.hasPointer


readonly canSavePicture: boolean

Whether savePicture can reach a phone now (see Play.canSavePicture); false before start.

Easy.canSavePicture


readonly muted: boolean

The screen’s sound is off (see StartInfo.muted); false before start.

Easy.muted


readonly orientation: Orientation

The screen’s orientation at the start (see Play.orientation); ‘landscape’ before start.

Easy.orientation


readonly safeArea: Readonly<SafeArea>

What a phone’s notch and home bar cover, fractions of the viewport (see Play.safeArea); zeros before start.

Easy.safeArea


readonly view: BackdropView | null

Where the camera image is, with any backdrop; null if the host didn’t say, and before start.

Easy.view


readonly device: DeviceHint | null

What the screen knows about the device (see Play.device); null if it said nothing, and before start.

Easy.device


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.

Easy.drawAvatar


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.

Easy.smoothedBody


readonly avatars: 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.

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.

K extends "players" | "backdrop" | Gesture | "pause" | "resume" | "break-start" | "turn" | "capabilities" | "hands" | "start" | "shape" | "break-end"

K

(data) => void

() => void

const off = FabiPlay.on('clap', ({ player }) => fire(player))

Easy.on


ready(): void

Say the game is loaded; done for you on page load unless the script tag says data-ready=“manual”.

void

Easy.ready


score(score, player?): void

The score so far, for the screen to show; player 1 unless said (with input ‘remote’, the child playing now).

number

number

void

Easy.score


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.

BreakReason

Promise<boolean>

Easy.break


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.

number | object[]

void

Easy.end


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.

Partial<Record<Action, string>>

Omit<KeyboardOptions, "target">

void

FabiPlay.keys({ jump: 'Space', left: 'ArrowLeft', right: 'ArrowRight' })

Easy.keys


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.

Omit<PointerOptions, "target">

void

Easy.pointer


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.

PictureSource

string

Promise<PictureResult>

if (FabiPlay.canSavePicture) FabiPlay.savePicture(canvas, { title: 'Il nostro muro' })

Easy.savePicture


reportStats(stats): void

For engines, debug only: how the game draws now (see Play.reportStats). Dropped before start.

GameStats

void

Easy.reportStats


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.

Point

Point

Easy.toScreen


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.

number | PlayerFrame

HandSide

Point | null

Easy.aim


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.

number | PlayerFrame

string

Easy.avatarOf