@fabi-play/engine

中文文档
0.9.0发布于 2026/11/14SEE LICENSE IN LICENSETypeScriptES Module零依赖近 30 天下载 2053

A small 2D engine for Fabi Play games: a 720-unit stage, sprites, shapes, text, particles, tweens, sound, the players' hands and avatars, on WebGL (1 or 2) or Canvas 2D.

原始使用文档
文档目录7 节
  1. npm
  2. Script tag
  3. Hands, orientation, safe area
  4. Filters
  5. Node pools
  6. Size
  7. License

@fabi-play/engine

A small 2D engine for Fabi Play games: a 720-unit stage, sprites, shapes, text, particles, tweens, sound, the players' hands and avatars, on WebGL (1 or 2) or Canvas 2D.

npm

npm install @fabi-play/sdk @fabi-play/engine
import { connect } from '@fabi-play/sdk'
import { createEngine } from '@fabi-play/engine'

const play = await connect()
const engine = await createEngine({ play })
engine.stage.add(engine.avatars())
engine.start()
play.ready()

@fabi-play/sdk is a peer dependency (the engine draws the avatars with the SDK's copy). ESM only, types included.

Bundlers that resolve the development export condition (Vite and webpack in development) get dist/index.development.js: readable, with development checks (a warning when a node is used after destroy() or after a node pool's release()). Production builds get dist/index.js, without them. Bundling the engine's source instead (inside the workspace), the checks are off unless the bundler defines __DEV__ as true.

Script tag

Load the SDK first, then the engine, each pinned with its SRI hash (https://cdn.fabiplay.app/engine/<version>/integrity.json):

<script src="https://cdn.fabiplay.app/sdk/0.1.0/fabi-play.umd.min.js" integrity="sha384-…" crossorigin="anonymous"></script>
<script src="https://cdn.fabiplay.app/engine/0.1.0/fabi-play-engine.lite.umd.min.js" integrity="sha384-…" crossorigin="anonymous"></script>
<script>
  FabiEngine.createEngine({ play: FabiPlay }).then((engine) => engine.start())
</script>
FileWhat
fabi-play-engine.lite.umd.min.jsrecommended: takes the avatars and smoothing from the SDK's script (global FabiEngine)
fabi-play-engine.umd.min.jseverything inside
*.umd.jsthe same, readable, with the development checks (warnings for nodes used after destroy() or a pool's release())
fabi-play-engine[.lite].jsthe classic scripts (IIFE): set window.FabiEngine
fabi-play-engine[.lite].d.tstypes for script-tag games (FabiEngine.Sprite, …)

Docs: https://docs.fabiplay.app/engine/overview/.

Hands, orientation, safe area

engine.hands() (stage units), engine.touched(node) and the rings of engine.handMarkers() are where the hands aim, with the protocol's aimPoint: on a TV or a tablet (landscape) on the avatar's hand, or on the real one over the video, as before; on a phone held upright (engine.orientation === 'portrait'), where the camera image is small at the bottom, the arms' reach around the shoulders stretched to the whole stage, so arms straight up touch near the top (y ≈ 0.15 × 720) and arms out reach the sides, held for 300 ms when the camera loses a wrist. The avatars are still drawn through the view (engine.view), small at the bottom. Games need no change; to draw on the body itself, use the SDK's toScreen(wrist).

engine.safeArea is what a phone's notch and home bar cover, in fractions of the viewport ({ top, bottom, left, right }, each 0–0.25, zeros on a TV): keep the HUD and targets out of it, e.g. a score at y = engine.safeArea.top * 720 + 24.

Filters

Any node can go through filters: colour filters, blur and drop shadows draw the same on WebGL and Canvas 2D; custom shaders are WebGL only. Each factory is its own export, so a game bundles only the ones it imports.

import { blur, dropShadow, shader, tint } from '@fabi-play/engine'

card.filters = [dropShadow(0, 8, 6, 'rgba(0,0,0,0.35)')]
const flash = tint('#fff', 0)
enemy.filters = [flash]
engine.tween(flash, { amount: 1 }, 0.05).then(() => engine.tween(flash, { amount: 0 }, 0.2))
if (engine.supports.shaders) flag.filters = [shader({ fragment: '…', uniforms: { uAmp: 0.004 } })]

tint, brightness, contrast, saturate, grayscale, sepia, hueRotate, invert, colorMatrix, blur, dropShadow, shader. Blur radii are capped per tier (32 / 16 / 0 units: off on the low tier); engine.supports says what draws here. Guide: https://docs.fabiplay.app/engine/filters/.

Node pools

For games that spawn many nodes a second: nodePool(factory, { max, reset }) gives nodes back reset to how the factory made them, instead of destroying and making them again. An import of its own (FabiEngine.nodePool on script tags).

import { nodePool } from '@fabi-play/engine'

const coins = nodePool(() => engine.shape({ type: 'circle', r: 16, fill: '#FBD46A' }), { max: 40 })
const coin = layer.add(coins.get({ x: 200, y: -20 }))
engine.tween(coin, { y: 740 }, 2, 'linear').then(() => coins.release(coin))

Size

pnpm size checks every build against size-budget.json (gzip -9), and what a game importing only createEngine bundles from the npm build. The first release (0.1.0) carries filters, node pools, the WebGL state cache, structural cache keys and an allocation-free hot path: the npm index.js went from 30.3 to 40.1 KB gzip during its development, the script tags by the same ~10 KB (they carry everything). A bundled game pays only for what it imports: with createEngine alone, 32.9 KB (29.1 before). The filter runtime (the GL passes and programs, the Canvas 2D plans) comes in with the first filter factory a game imports: one factory adds 3.6 KB, all twelve 5.2 KB. nodePool is an import of its own: 0.7 KB. The 3.8 KB every game pays (the WebGL state cache, layer bounds, structural cache keys, the allocation-free hot path, the filter hook and engine.supports) are explained in the budget file's notes.

License

Fabi Play Kit License: free to use, for making games and tools for Fabi Play only. See LICENSE.

版本与发布记录

@fabi-play/engine 共发布 10 个版本,首次发布于 2026/11/05;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.9.0latest2026/11/14今天
0.8.02026/11/14今天
0.7.12026/11/095 天前
0.7.02026/11/095 天前
0.4.02026/11/086 天前
0.5.02026/11/086 天前

关于 @fabi-play/engine 的常见问题

@fabi-play/engine 是什么?

A small 2D engine for Fabi Play games: a 720-unit stage, sprites, shapes, text, particles, tweens, sound, the players' hands and avatars, on WebGL (1 or 2) or Canvas 2D.

如何安装 @fabi-play/engine?

在项目目录运行 npm install @fabi-play/engine,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@fabi-play/sdk(^0.9.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fabi-play/engine 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fabi-play/engine 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@fabi-play/engine 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@fabi-play/engine 可以商用吗?

@fabi-play/engine 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@fabi-play/engine 的下载量有多少?

根据 npm 官方下载统计,@fabi-play/engine 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,053 次,日均约 68 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fabi-play/engine 还在维护吗?

最新版本 0.9.0 发布于 2026/11/14(今天);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/11/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。