Draw. SpriteAnimator

SpriteAnimator - A character's animations by name, like idle, walk and attack, and the one showing now

  • Each clip is a SpriteAnimation and keeps its own mode, loop, play or pingPong
  • set starts a clip over only when it changes or a play of it has ended, so it can be called every update
  • Read tileInfo each frame for the frame to draw, as with a SpriteAnimation

Constructor

new SpriteAnimator(clips)

Create an animator from its clips, showing the first one

Parameters:
NameTypeDescription
clipsObject.<string, SpriteAnimation>

The clips by name

Example
const hero = new SpriteAnimator({
    idle:   new SpriteAnimation(tile(0, 16), 2, .4),
    walk:   new SpriteAnimation(tile(2, 16), 4, .1),
    attack: new SpriteAnimation(tile(6, 16), 3, .05).play(),
});
hero.set('attack', ()=> hero.set('idle')); // back to idle when the attack ends
// in update: this.tileInfo = hero.tileInfo;

Members

clip

The clip showing now

clips

Properties
TypeDescription
Object.<string, SpriteAnimation>

The clips by name

frame

The frame of the clip showing now

isDone

True once the clip showing now is a play that has ended

name

Properties
TypeDescription
string

The name of the clip showing now

tileInfo

The tile of the frame showing now

Methods

set(name, onEndopt) → {SpriteAnimator}

Show a clip, starting it over in its own mode unless it is showing and has not ended

Parameters:
NameTypeAttributesDescription
namestring

The clip's name

onEndfunction<optional>

Called once when a play clip ends, as with SpriteAnimation.play

Returns:
Type: 
SpriteAnimator