Skip to content

Stage

engine.stage: the root group, 720 units high, as wide as the viewport’s aspect.

blend: Blend

‘add’ for glows and sparks; ‘normal’ otherwise.

Group.blend


parent: Group | null

The group the node is in, or null.

Group.parent


hitRadius: number | null

Hit tests use a circle of this radius (local units) around the origin instead of the rectangle; null: the rectangle.

Node.hitRadius


clip: ClipRect | null

Clips the node and its children to this rectangle, in the node’s own units (x, y, width, height). While no rotation is above it, the renderer clips on whole pixels without breaking the batch; rotated, it is drawn as a mask. Clips nest (they intersect). Hit tests ignore it.

list.clip = { x: 0, y: 0, width: 400, height: 300 } // a scrolling list: move its children, not the clip

Node.clip


mask: Node | null

Shows the node and its children only where this node is opaque, times its alpha: a circle, a star, a text, any node. The mask is placed as a child of the masked node would be, and is not drawn otherwise (keep it out of the stage). The masked node is drawn into a layer: about two full-canvas composites per mask, so use a few.

photo.mask = engine.shape({ type: 'circle', r: 80, fill: '#fff' })

Node.mask


filters: Filter[] | null

Filters the node and its children go through, in order: tint, brightness, contrast, saturate, grayscale, sepia, hueRotate, invert, colorMatrix, blur, dropShadow (the same on WebGL and Canvas 2D), shader (WebGL only). The node is drawn into a layer and composited through them (the filters inside a clip and under a mask). Change their fields freely (flash.amount = 0.5, tweens); null or [] for none.

import { blur, dropShadow } from '@fabiplay/engine'
card.filters = [dropShadow(0, 8, 6, 'rgba(0,0,0,0.35)')]
background.filters = [blur(6)]

Stage.filters


anchorX: number

Horizontal anchor, 0–1 of the width: 0 left, 0.5 the middle.

Group.anchorX


anchorY: number

Vertical anchor, 0–1 of the height: 0 top, 0.5 the middle.

Group.anchorY


readonly children: Node[]

The nodes in it, in drawing order (one shared empty array until the first add). Safe to destroy() them while iterating.

Group.children


dead: boolean

@internal: a child was destroyed.

Group.dead


readonly width: number

Stage units: width follows the viewport’s aspect, height is always 720.

Group.width


readonly height: number

Always 720 (STAGE_HEIGHT).

Group.height


readonly safe: object

The 16:9 area in the middle, for what must be seen on any screen.

x: number

y: number

w: number

h: number

get x(): number

Position in the parent, stage units.

number

set x(v): void

number

void

Group.x


get y(): number

Position in the parent, stage units (y downwards).

number

set y(v): void

number

void

Group.y


get rotation(): number

Radians, clockwise.

number

set rotation(v): void

number

void

Group.rotation


get scaleX(): number

Horizontal scale (negative: mirrored).

number

set scaleX(v): void

number

void

Group.scaleX


get scaleY(): number

Vertical scale.

number

set scaleY(v): void

number

void

Group.scaleY


get alpha(): number

0–1, multiplied down the tree.

number

set alpha(v): void

number

void

Group.alpha


get visible(): boolean

Hidden nodes and their children are not drawn. Hit tests (engine.touched, engine.hits) still see them.

boolean

set visible(v): void

boolean

void

Group.visible


get destroyed(): boolean

Set by destroy(): the node is gone (its handle is stale).

boolean

Group.destroyed


get world(): Mat

The transform to the stage, as of the last draw (or updateWorld): a view on the node store, written in place. Read it when you need it: a view kept across frames stops following the node once the store grows (new arrays).

Mat

Group.world


get data(): Record<string, any>

Free for the game: speed, state, anything (made on first use).

Record<string, any>

set data(v): void

Record<string, any>

void

Group.data


get scale(): number

Both scales: reads scaleX, sets scaleX and scaleY.

number

set scale(v): void

number

void

Group.scale


get z(): number

Drawing order among siblings: higher on top (equal: order of adding).

number

set z(v): void

number

void

Group.z


get tint(): number

A colour multiplied with the node’s pixels (white: none), as 0xRRGGBB or CSS.

number

set tint(v): void

ColorLike

void

Group.tint


set anchor(v): void

Sets anchorX and anchorY: a number for both, or { x, y }. 0 top-left, 0.5 the middle.

number | { x: number; y: number; }

void

Group.anchor

set(props): this

Sets many fields at once.

NodeProps

this

Group.set


updateWorld(): Mat

world, computed now from the parents (for hit tests between draws).

Mat

Group.updateWorld


add<T>(node, …more): T

Adds nodes (moving them from another group); returns the first, so const s = stage.add(engine.sprite(…)).

T extends Node

T

…Node[]

T

Group.add


remove(node): void

Takes a node out of the group (without destroying it).

Node

void

Group.remove


clear(): void

Destroys every child.

void

Group.clear


destroy(): void

Destroys the group and every child.

void

Group.destroy


draw(ctx, alpha, tint): void

Draws the children, in order of z, each placed (its world composed, store.ts place) right before it is drawn, when it or a parent moved. The outermost draw begins a pass; a group in no group drawn inside it (a mask) has been placed anew by its caller, so everything under it is composed.

DrawContext

number

number

void

Group.draw