Tweens and particles
Tweens
Section titled “Tweens”await engine.tween(star, { scale: 1.6, alpha: 0 }, 0.25)star.destroy()engine.tween(target, to, seconds, ease?) eases numeric fields of target from where they are to the values in
to, over seconds. The target can be a node or any object with numbers.
- It runs on game time: it stops while the game is paused or Fabi Play shows a break.
- It returns a promise that resolves at the end, with
stop(): stopping it leaves the fields where they are and resolves the promise. A tween of a destroyed node stops there;node.destroy()stops all its tweens. - The fourth argument is an easing name, an easing function (
(t) => eased t, both 0 to 1), or options:
| Option | Default | What it is |
|---|---|---|
ease |
'quadOut' |
An easing name or function |
delay |
0 |
Seconds before it starts; the start values are read then |
onUpdate |
Called every step with the eased progress, 0 to 1 |
The easings, in EASE: linear, quadIn, quadOut (the default), quadInOut, cubicOut, sineInOut, backOut
(overshoots a little), elasticOut, bounceOut.
engine.tween(banner, { y: 360 }, 0.6, 'bounceOut')engine.tween(hint, { alpha: 1 }, 0.3, { delay: 2, ease: 'sineInOut' })const pulse = engine.tween(button, { scale: 1.2 }, 0.5, { onUpdate: (k) => (glow.alpha = k) })pulse.stop()Sequences. Tweens are promises, so a short sequence is a chain of awaits:
async function popIn(node: Node) { await engine.tween(node, { scale: 1.2 }, 0.15, 'backOut') await engine.tween(node, { scale: 1 }, 0.1)}For longer ones, with steps that overlap, labels, repeats or yoyo, use a timeline.
Particles
Section titled “Particles”const sparks = stage.add( engine.particles({ type: 'circle', r: 6, fill: '#fff' }, { max: engine.tier.scale(200), gravity: 400 }),)
sparks.burst(star.x, star.y, engine.tier.scale(24), { tint: hand.color, speed: [100, 300] })engine.particles(frame, options) makes a pooled emitter: a node that draws many small particles from one frame.
The frame is a shape description (baked for you), or the name of a loaded or baked frame.
The particles live in fixed arrays allocated once, so bursts allocate nothing while playing. They move with their speed, gravity and drag, fade out over their life, and shrink or grow. They stop on pause like everything else.
The emitter’s options, for all its particles (and the node’s own fields, such as z):
| Option | Default | What it is |
|---|---|---|
max |
200 |
The pool: most particles alive at once. Fixed; scale it with engine.tier.scale(n) |
blend |
'normal' |
'add' for glowing sparks |
gravity |
0 |
Stage units per second², downwards |
drag |
1 |
Velocity kept per second, 0 to 1 (1: none lost) |
emitter.burst(x, y, n, options) starts n particles at (x, y) in the emitter’s own space (the stage’s, if
the emitter is not moved). Past the pool’s size the oldest particles are reused. Each option takes a number, and
speed, life and scale also a [min, max] range:
| Option | Default | What it is |
|---|---|---|
speed |
200 |
Stage units per second |
life |
0.8 |
Seconds |
angle, spread |
full circle | The direction (radians) and the spread around it |
scale |
1 |
At birth and at death, [birth, death] |
spin |
0 |
Radians per second, either way |
tint |
A colour multiplied with the frame, for example the player’s colour (hand.color) |
|
alpha |
1 |
At birth; they fade out over their life |
emitter.alive is the number of particles alive, and emitter.clear() removes them all at once.
Glows. Additive particles (blend: 'add') look great over a dark sky and are cheap on WebGL. Use them on the
high tier (engine.tier.effects); on Canvas 2D additive blending can be slow.
const sparks = stage.add( engine.particles( { type: 'circle', r: 6, fill: '#fff' }, { max: engine.tier.scale(200), blend: engine.tier.effects ? 'add' : 'normal' }, ),)