Docs
Playing clips
One-shots, loops, chaining and speed: how play() behaves and what its promise means.
play(name) starts a clip and returns a promise that resolves when the clip is back on the still picture. The element then stays on that still. A clip made as a loop keeps playing until another clip starts.
await coin.play('spin'); // one-shot, resolves on the still
await coin.play('pop', { speed: 2 }); // twice as fast
console.log(coin.clips); // ['win', 'idle', 'spin', ...]Chaining
Every clip starts and ends on the same still, so any clip can follow any other without a jump: from the still, the next clip simply starts. Starting a clip while another is moving replaces it at once, faded in over it in about a tenth of a second, so the change never pops. To let a one-shot finish first, pass wait: the next clip then starts on the still they share. A newer request replaces a waiting one, and the replaced one's promise resolves.
hero.play('celebrate');
hero.play('wave', { wait: true }); // starts when celebrate ends, never over itThe promise always resolves
If the element is destroyed mid-clip, its promise still resolves. A sequence awaiting a clip never hangs. Asking for a clip the element does not have rejects with the list of clips it has.