Shape
A shape baked once into the atlas (see ShapeSpec); changing spec bakes again (do it rarely, not every frame). A roundRect resizes freely with width and height (panels, progress bars).
Example
Section titled “Example”const star = stage.add(engine.shape({ type: 'star', r: 40, fill: '#FBD46A', stroke: '#fff', lw: 4 }, { x: 200, y: 100 }))Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Shape(
kernel,spec,props?):Shape
Use engine.shape(spec, props).
Parameters
Section titled “Parameters”kernel
Section titled “kernel”props?
Section titled “props?”Returns
Section titled “Returns”Shape
Overrides
Section titled “Overrides”Properties
Section titled “Properties”blend:
Blend
‘add’ for glows and sparks; ‘normal’ otherwise.
Inherited from
Section titled “Inherited from”parent
Section titled “parent”parent:
Group|null
The group the node is in, or null.
Inherited from
Section titled “Inherited from”hitRadius
Section titled “hitRadius”hitRadius:
number|null
Hit tests use a circle of this radius (local units) around the origin instead of the rectangle; null: the rectangle.
Inherited from
Section titled “Inherited from”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.
Example
Section titled “Example”list.clip = { x: 0, y: 0, width: 400, height: 300 } // a scrolling list: move its children, not the clipInherited from
Section titled “Inherited from”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.
Example
Section titled “Example”photo.mask = engine.shape({ type: 'circle', r: 80, fill: '#fff' })Inherited from
Section titled “Inherited from”filters
Section titled “filters”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.
Example
Section titled “Example”import { blur, dropShadow } from '@fabiplay/engine'card.filters = [dropShadow(0, 8, 6, 'rgba(0,0,0,0.35)')]background.filters = [blur(6)]Inherited from
Section titled “Inherited from”anchorX
Section titled “anchorX”anchorX:
number
Horizontal anchor, 0–1 of the width: 0 left, 0.5 the middle.
Inherited from
Section titled “Inherited from”anchorY
Section titled “anchorY”anchorY:
number
Vertical anchor, 0–1 of the height: 0 top, 0.5 the middle.
Inherited from
Section titled “Inherited from”slice:
number|Insets
Nine-slice insets in frame pixels (0: none, or the frame’s own): one number for all sides, or [top, right, bottom, left]. The corners keep their size when the sprite is resized.
Inherited from
Section titled “Inherited from”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get x():
number
Position in the parent, stage units.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set x(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get y():
number
Position in the parent, stage units (y downwards).
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set y(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”rotation
Section titled “rotation”Get Signature
Section titled “Get Signature”get rotation():
number
Radians, clockwise.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set rotation(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”scaleX
Section titled “scaleX”Get Signature
Section titled “Get Signature”get scaleX():
number
Horizontal scale (negative: mirrored).
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set scaleX(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”scaleY
Section titled “scaleY”Get Signature
Section titled “Get Signature”get scaleY():
number
Vertical scale.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set scaleY(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get alpha():
number
0–1, multiplied down the tree.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set alpha(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”visible
Section titled “visible”Get Signature
Section titled “Get Signature”get visible():
boolean
Hidden nodes and their children are not drawn. Hit tests (engine.touched, engine.hits) still see them.
Returns
Section titled “Returns”boolean
Set Signature
Section titled “Set Signature”set visible(
v):void
Parameters
Section titled “Parameters”boolean
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”destroyed
Section titled “destroyed”Get Signature
Section titled “Get Signature”get destroyed():
boolean
Set by destroy(): the node is gone (its handle is stale).
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”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).
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get data():
Record<string,any>
Free for the game: speed, state, anything (made on first use).
Returns
Section titled “Returns”Record<string, any>
Set Signature
Section titled “Set Signature”set data(
v):void
Parameters
Section titled “Parameters”Record<string, any>
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get scale():
number
Both scales: reads scaleX, sets scaleX and scaleY.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set scale(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get z():
number
Drawing order among siblings: higher on top (equal: order of adding).
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set z(
v):void
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get tint():
number
A colour multiplied with the node’s pixels (white: none), as 0xRRGGBB or CSS.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set tint(
v):void
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get frame():
Frame|null
What it shows: set a frame or the name of a loaded or baked one (an animation swaps it every few frames).
Returns
Section titled “Returns”Frame | null
Set Signature
Section titled “Set Signature”set frame(
f):void
Parameters
Section titled “Parameters”string | Frame | null
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”anchor
Section titled “anchor”Set Signature
Section titled “Set Signature”set anchor(
v):void
Sets anchorX and anchorY (until then the frame’s own origin is used).
Parameters
Section titled “Parameters”number | { x: number; y: number; }
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”naturalWidth
Section titled “naturalWidth”Get Signature
Section titled “Get Signature”get naturalWidth():
number
The content size the frame has, stage units (without its margin; untrimmed).
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”naturalHeight
Section titled “naturalHeight”Get Signature
Section titled “Get Signature”get naturalHeight():
number
The content height the frame has, stage units (without its margin; untrimmed).
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get spec():
ShapeSpec
What it is: setting it bakes the shape again.
Returns
Section titled “Returns”Set Signature
Section titled “Set Signature”set spec(
s):void
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Get Signature
Section titled “Get Signature”get width():
number
Local width, stage units: the shape’s own until set (a roundRect is redrawn to it, others stretched).
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set width(
v):void
Local width, stage units: the frame’s own (naturalWidth) until set; setting it stretches the sprite.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”height
Section titled “height”Get Signature
Section titled “Get Signature”get height():
number
Local height, stage units: the shape’s own until set.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set height(
v):void
Local height, stage units: the frame’s own (naturalHeight) until set; setting it stretches the sprite.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Methods
Section titled “Methods”set(
props):this
Sets many fields at once.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”destroy()
Section titled “destroy()”destroy():
void
Removes the node: invisible at once (its parent null), out of its group’s children at the end of the frame. Its tweens stop.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”updateWorld()
Section titled “updateWorld()”updateWorld():
Mat
world, computed now from the parents (for hit tests between draws).
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”draw()
Section titled “draw()”draw(
ctx,alpha,tint):void
Draws the frame (the engine calls it).
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”void