Clips and timeline control

A clip is one named animation of a thing: main, walk, idle, jump. All clips of a component, a frame or a rig share the same layers. A clip only changes values (keyframes and per-clip settings), never adds or removes layers, so formulas that point at those layers keep working whatever clip is playing.

Try it

Make a component with two clips, idle and walk. Put an instance on the canvas, call it Hero, and give a button this click event:

// Button: on click
Hero.play('walk')

Press Play and click the button: Hero switches to walk and starts it from its first frame. Stop brings the scene back to how it was before you pressed Play.

What a value is made of

When several things set the same property, the first one in this list wins:

1. a formula on the property; 2. keyframes of the clip that is playing; 3. the clip's own setting for the property; 4. the value you set on the layer.

Component instances

Hero.play()          // keep the current clip, start the clock
Hero.play('walk')    // switch to walk and start it from its first frame
Hero.stopPlayback()  // stop the instance's clock where it is
Hero.activeClip      // the clip's name, readable in any formula

activeClip can also be written. Writing the name that is already playing does nothing, so a formula can choose a clip on every frame without restarting it:

// Hero.activeClip
Hero.speed > 0 ? 'walk' : 'idle'

Here speed is a property you added to the component yourself. Other formulas that read Hero.activeClip update when it changes, whether the switch came from outside or from a script inside the component.

In the panel, an instance also has Clip, Play mode (clip default, loop, play once, single frame) and Initial frame. Clip can be keyed on the timeline, so a clip switch can be part of the animation.

play() and stopPlayback() act while the scene is playing. In the editor, outside Play, they do nothing.

Rigs

A skeleton blends from one clip into the next instead of cutting:

// Rig1: on click
Rig1.play('jump', { duration: 0.2, repeat: false })
  • duration — crossfade length in seconds. 0 swaps at once.
  • curve — easing of the crossfade, 'easeInCubic' by default.
  • animateFrom — keep the outgoing clip moving during the fade (frozen by default).
  • animateTo — hold the incoming clip on its first frame during the fade.
  • repeat — loop the clip.
  • startPhase — where the clip starts, in ticks (240 per second). Give several instances of the same walk different phases so they do not step in sync.

Rig1.stop() ends the scripted clips and gives the rig back to the timeline. A clip name the rig does not have is ignored.

Sound

Audio layers have their own controls: play(), stop(), pause() and resume(), and read-only values for formulas: playing, position, duration, rms and peak. rms and peak follow the loudness while it plays, so a shape can pulse with the music:

// Speaker.w
100 + Music.rms * 200

Reacting to time

Every formula can read time (seconds since Play), frame (frames since Play) and dt (seconds since the last frame). The tick event runs once per frame with the same three values on event:

// Hero: on tick
if (event.frame % 120 == 0) Hero.play('blink')

What is not there yet

  • No event fires when a clip ends. A clip set to Play once stops on its last frame.
  • No jump to a frame from a script (no gotoAndPlay). Use Initial frame, or a jump keyframe on the timeline.

See also

Formo

The browser studio where drawings become animations, toys, and games. Your files, nothing to install.