Skip to content

Timeline

A single tween moves some fields; a few tweens in a row are easy to chain with await. For anything longer (a banner that pops in, holds and fades out; a title, then the stars, then a button) a timeline places the steps on one clock and plays, pauses, repeats or seeks them as one.

const banner = stage.add(engine.text('Level 2', { x: 640, y: 300, size: 72, outline: true, alpha: 0, scale: 0.6 }))
await engine
.timeline()
.to(banner, { alpha: 1, scale: 1 }, 0.4, 'backOut')
.wait(1.2)
.to(banner, { alpha: 0, y: 260 }, 0.4)
banner.destroy()

engine.timeline(options?) makes an empty timeline; chain steps on it. It starts on the next frame, so build it in one go.

Each step goes after the previous one, unless at says where.

Step What it does
.to(target, values, seconds, ease?) Eases numeric fields to values, like engine.tween. The fourth argument is an easing name or function, or { ease, at, delay, onUpdate }
.set(target, values, at?) Sets fields at once, at that point
.call(fn, at?) Calls fn at that point
.label(name, at?) Names a point, to place other steps from it
.wait(seconds) Leaves a gap at the end

A target is a node or any object with numbers, as for tweens. A step reads its starting values when it first starts, so it continues from wherever the previous steps left the fields.

at Where the step starts
(none) At the end of the timeline so far
1.5 1.5 seconds from the start
'cheer' At the label cheer
'cheer+=0.2', 'cheer-=0.2' 0.2 seconds after or before the label
'+=0.5', '-=0.5' 0.5 seconds after or before the end so far (overlapping the previous step)
'<', '<+=0.1' Where the previous step started (together with it), or 0.1 seconds later

An unknown label is made at the end. In .to, a delay is added to at.

engine
.timeline()
.to(title, { alpha: 1, scale: 1 }, 0.4, 'backOut')
.label('cheer')
.to(stars, { y: 300 }, 0.6, { at: 'cheer', ease: 'bounceOut' })
.to(button, { alpha: 1 }, 0.3, { at: 'cheer+=0.2' })
.call(() => engine.sound.tone(880, 0.2), 'cheer')
Option Default What it is
repeat 0 Plays after the first: 2 plays three times in all, -1 until stopped
yoyo false With repeat, every other play runs backwards
delay 0 Seconds before it starts
paused false Made paused: call resume() to start it
onComplete Called when the last play ends (not on stop())
  • pause() and resume(); seek(seconds) or seek('label') jumps there, playing or paused.
  • stop() ends it where it is.
  • It is awaitable: await it (or .then) for its end, which comes after its last play or at stop(). With repeat: -1 it only ends at stop().
  • duration (one play, seconds), time (the playhead in the current play), paused and finished say where it is.
const pulse = engine.timeline({ repeat: -1, yoyo: true }).to(button, { scale: 1.1 }, 0.5, 'sineInOut')
// later
pulse.stop()
  • On game time, like tweens: it freezes while the game is paused or Fabi Play shows a break.
  • By time: a step writes its fields only once the playhead has reached it, and a later step on the same field takes over from it. Going back (yoyo, a repeat, seek) puts each field back to the starting value of its steps.
  • Calls fire whenever the playhead crosses them, in either direction: a call in a yoyo fires on the way back too.
  • Steps on a destroyed node are skipped, so destroying a node in the middle of its timeline is safe.