Skip to content

Getting started

Fabi Play brings body movements into your game, which stays on your own site: as keys, as a pointer, or as events. The game remains an HTML5 page, with whatever engine it already uses (Phaser, PixiJS, Construct, Godot web, Unity WebGL, hand-written canvas).

There are three levels. Start with the first and only move up if you need to.

Level What you add For
0 One script tag, no code Games that already play with the keyboard or the mouse
1 FabiPlay.on('jump', …) Games that want real movements, hands and bodies
2 import { connect } from '@fabiplay/sdk' Games built with a bundler (Vite, esbuild, webpack)

If you have no engine of your own, the Fabi Play engine sits on top of the SDK and does the canvas, the hands, the avatars and mirror mode for you.

  • Script tag from your site: copy fabi-play.js from the @fabiplay/sdk package (dist/fabi-play.js) to your site and serve it from there.

  • Script tag from cdn.fabiplay.app: every version of the SDK is on https://cdn.fabiplay.app/sdk/<version>/, immutable. Load it with its Subresource Integrity hash (from integrity.json in the same folder, or in the npm package’s dist/) and crossorigin="anonymous". It is the only address outside your site a game page may load anything from (see Publishing):

    <script
    src="https://cdn.fabiplay.app/sdk/0.1.0/fabi-play.umd.min.js"
    integrity="sha384-…"
    crossorigin="anonymous"
    ></script>
  • npm: npm install @fabiplay/sdk. The packages are published under the @fabiplay scope from 0.9.0; earlier versions were @fabi-play/*.

Load fabi-play.js before the game’s own scripts: it mutes the game’s audio during ads, and it can only see the Web Audio contexts created after it (see Pause, breaks and audio).

For games that already play with the keyboard or the mouse, just add the script to the page.

<!-- runner: Space jumps, arrows change lane -->
<script src="fabi-play.js" data-keys="jump:Space,left:ArrowLeft,right:ArrowRight,squat:ArrowDown"></script>
<!-- mouse game: the child's hand moves the pointer, holding it still for 0.8 seconds is a click -->
<script src="fabi-play.js" data-pointer="any"></script>

The script tells Fabi Play that the game is ready by itself when the page finishes loading. Which movement presses which key, and how the hand drives the pointer, is in Keys and pointer.

When the game wants real movements rather than keys, listen for them by name on FabiPlay, the global the script sets:

FabiPlay.on('jump', ({ player }) => hero(player).jump())
FabiPlay.on('lane-left', () => hero(1).left())
FabiPlay.on('hands', ({ player, right }) => aim(player, right)) // x, y from 0 to 1
FabiPlay.on('shape', ({ shape }) => shape === 'arms-wide' && openBridge())
FabiPlay.on('start', ({ ageRange }) => setDifficulty(ageRange)) // '3-5', '6-8' or '9-12'
FabiPlay.on('pause', () => game.pause())
// end of a level: Fabi Play may show an ad here (see "Pause, breaks and audio")
await FabiPlay.break('level')
FabiPlay.end(120) // or [{ player: 1, score: 120, stars: 3 }, ...]

Every event, and what each one carries, is in Events and bodies.

If the game loads assets after the page’s load event, put data-ready="manual" on the script and call FabiPlay.ready() when it is ready. Fabi Play waits 10 seconds for it; after that the TV closes the game.

<script src="fabi-play.js" data-ready="manual"></script>
<script>
loadEverything().then(() => FabiPlay.ready())
</script>

For bundler users. connect() waits for Fabi Play to start the game and resolves with a Play object:

import { connect, keyboard, pointer } from '@fabiplay/sdk'
const play = await connect()
play.on('gesture', (g) => { /* g.player, g.gesture: 'jump', 'lane-left', … */ })
play.on('frame', (f) => { /* f.players: all 33 body points of every player */ })
keyboard(play, { jump: 'KeyW' }, { player: 2 }) // the second player with WASD
play.ready()

connect() rejects after 10 seconds without a host (the page was not opened from Fabi Play or its simulator), or if the host speaks another protocol version.

Play names its events after the protocol (frame, gesture, break-done), while FabiPlay has one event per movement (jump, clap, …). If you prefer the named events with npm, wrap the connection:

import { connect, easy } from '@fabiplay/sdk'
const FabiPlay = easy(connect()) // the same API as the script tag's global
FabiPlay.on('jump', () => hop())
FabiPlay.on('start', ({ players, ageRange, backdrop }) => setup(players, ageRange, backdrop))
FabiPlay.on('jump', ({ player }) => jump(player))
FabiPlay.on('players', ({ players }) => (bodies = players))
FabiPlay.score(10, 1) // score, then player (1 if left out)
await FabiPlay.break('level')
FabiPlay.end([{ player: 1, score: 120 }]) // stars: 2 if left out