gameify. Animator

Manages animations for sprites, text, etc. Usually used via the Sprite or Text object

Constructor

new Animator(parent)

Parameters:
NameTypeDescription
parentObject

The object to animate

Example
mySprite = new gameify.Sprite(0, 0, new gameify.Image("player.png"));

let myAnimation = new gameify.Animation(frames, { duration: 200, loop: true });

mySprite.animator.set('idle', myAnimation);
mySprite.animator.play('idle');

Members

animationProgress

The time the animation started playing

(readonly) animations

The animations currently assigned to the animator. Use Animator.set() and Animator.play() to add and play animations

(readonly) currentAnimation

The animation that is currently playing (or undefined if not playing). Use Animator.play() to change the current animation being played.

(readonly) currentAnimationName

The name of the current animation (or undefined if not). Use Animator.play() to change the current animation being played.

parent :Object

The object that this animator is attached to

Type:
  • Object

playing

If an animation is currently playing

Methods

fromJSON(data, ref) → {gameify.Animation}

Creates a object from JSON data

Parameters:
NameTypeDescription
dataObject | Array

Serialized object data (from object.toJSON)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
gameify.Animation

pause()

Pause the animation

play(name)

Play an animation, or resume it if it's paused. If the animation is paused or already playing, this function does not reset the animation (use Animator.stop() to reset the animation).

Parameters:
NameTypeDescription
nameString

The name of the animation

resume()

Resume the animation

set(name, animation)

Add an animation to the animations list

Parameters:
NameTypeDescription
nameString

The name of the animation

animationgameify.Animation

The animation

stop()

Stop & reset the animation

toJSON(keyopt, ref) → {Object}

Convert the object to JSON

Parameters:
NameTypeAttributesDescription
keystring<optional>

Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.)

reffunction

A function that returns a name for other objects, so they can be restored later

Returns:
Type: 
Object

update(delta)

Update the animation

Parameters:
NameTypeDescription
deltaNumber

The time, in miliseconds, since the last frame