Shaku

Shaku JS

Back To Table of Content

Animator

Animator

Implement an animator object that change values over time using Linear Interpolation. Usage example: (new Animator(sprite)).from({‘position.x’: 0}).to({‘position.x’: 100}).duration(1).play();

Kind: global class

new Animator(target)

Create the animator.

Param Type Description
target \* Any object you want to animate.

animator.speedFactor

Speed factor to multiply with delta every time this animator updates.

Kind: instance property of Animator

animator.ended ⇒ Boolean

Get if this animator finished.

Kind: instance property of Animator
Returns: Boolean - True if animator finished.

animator.update(delta)

Update this animator with a given delta time.

Kind: instance method of Animator

Param Type Description
delta Number Delta time to progress this animator by.

animator.then(callback) ⇒ Animator

Set a method to run when animation ends.

Kind: instance method of Animator
Returns: Animator - this.

Param Type Description
callback function Callback to invoke when done.

animator.smoothDamp(enable) ⇒ Animator

Set smooth damp. If true, lerping will go slower as the animation reach its ending.

Kind: instance method of Animator
Returns: Animator - this.

Param Type Description
enable Boolean set smooth damp mode.

animator.repeats(enable, reverseAnimation) ⇒ Animator

Set if the animator should repeat itself.

Kind: instance method of Animator
Returns: Animator - this.

Param Type Description
enable Boolean | Number false to disable repeating, true for endless repeats, or a number for limited number of repeats.
reverseAnimation Boolean if true, it will reverse animation to repeat it instead of just “jumping” back to starting state.

animator.reverseBackToStart() ⇒ Animator

If true, will reverse animation back to start values after done. This is equivalent to calling repeats(1, true).

Kind: instance method of Animator
Returns: Animator - this.

animator.from(values) ⇒ Animator

Set ‘from’ values. You don’t have to provide ‘from’ values, when a value is not set the animator will just take whatever was set in target when first update is called.

Kind: instance method of Animator
Returns: Animator - this.

Param Type Description
values \* Values to set as ‘from’ values. Key = property name in target (can contain dots for nested), value = value to start animation from.

animator.to(values) ⇒ Animator

Set ‘to’ values, ie the result when animation ends.

Kind: instance method of Animator
Returns: Animator - this.

Param Type Description
values \* Values to set as ‘to’ values. Key = property name in target (can contain dots for nested), value = value to start animation from.

animator.flipFromAndTo()

Flip between the ‘from’ and the ‘to’ states.

Kind: instance method of Animator

animator.duration(seconds) ⇒ Animator

Make this Animator update automatically with the gameTime delta time. Note: this will change the speedFactor property.

Kind: instance method of Animator
Returns: Animator - this.

Param Type Description
seconds Number Animator duration time in seconds.

animator.reset() ⇒ Animator

Reset animator progress.

Kind: instance method of Animator
Returns: Animator - this.

animator.play() ⇒ Animator

Make this Animator update automatically with the gameTime delta time, until its done.

Kind: instance method of Animator
Returns: Animator - this.