API Docs for: 1.4.0
Show:

Kiwi.Components.AnimationManager Class

Extends Kiwi.Component
Module: Components
Parent Module: Kiwi

The AnimationManager is used to handle the creation and use of spritesheet Animations on a GameObject based on the TextureAtlas it has. If the When the AnimationManager is instantiated it will loop through all of the Sequences on the TextureAtlas of the GameObject being used and will create a new Animation for each one. Now when you create a new Animation that animation will automatically be added as a new Sequence to the corresponding Texture. This way you don't need to create new Animations for a each Sprite that use's the same Texture.

Constructor

Kiwi.Components.AnimationManager

(
  • entity
  • [inheritSequences=true]
)
Kiwi.Components.AnimationManager

Parameters:

  • entity Kiwi.Entity

    The entity that this animation component belongs to.

  • [inheritSequences=true] Boolean optional

    If a new Animation should be created for each Sequence on the Entities TextureAtlas it is a part of or not.

Methods

_play

(
  • name
  • [index=null]
)
Kiwi.Animations.Animation private

An internal method used to actually play a Animation at a Index.

Parameters:

  • name String

    The name of the animation that is to be switched to.

  • [index=null] Number optional

    The index of the frame in the Sequence that is to play. If null, then it restarts the animation at the cell it currently is at.

Returns:

Kiwi.Animations.Animation:

Returns the current Animation that is now playing.

_setCurrentAnimation

(
  • name
  • [inheritFromTexture=true]
)
private

Internal method that sets the current animation to a Animation passed.

Parameters:

  • name String

    Name of the Animation that is to be switched to.

  • [inheritFromTexture=true] Booelan optional

    If the animation component should look on the texture atlas for a sequence with that name.

add

(
  • name
  • cells
  • speed
  • [loop=false]
  • [play=false]
  • [addToAtlas=true]
)
Kiwi.Animations.Animation public

Creates a new Animation (by creating a Sequence) that can then be played on this AnimationManager. If you pass to this the name of a Animation that already exists, then the previous Animation will be overridden by this new one. Note: If the Animation you have overridden was the currentAnimation, then the previous Animation will keep playing until a different Animation is switched to. By default new Animation Sequences are also added to the TextureAtlas, which can then be inherited. Returns the Animation that was created.

Parameters:

  • name String

    The name of the animation that is to be created.

  • cells Array

    An array of numbers, which are reference to each cell that is to be played in the Animation in order.

  • speed Number

    The amount of time that each cell in the Animation should stay on screen for. In seconds.

  • [loop=false] Boolean optional

    If when the Animation reaches the last frame, it should go back to the start again.

  • [play=false] Boolean optional

    If once created the animation should played right away.

  • [addToAtlas=true] Boolean optional

    If the new Sequence created should be added to the TextureAtlas or not.

Returns:

Kiwi.Animations.Animation:

The Animation that was created.

createFromSequence

(
  • sequence
  • [play=false]
)
Kiwi.Animations.Animation public

Creates a new Animation based on a Sequence that is passed. If you pass to this the name of a Animation that already exists, then the previous Animation will be overridden by this new one. Note: If the Animation you have overridden was the currentAnimation, then the previous Animation will keep playing until a different Animation is switched to. Returns the Animation that was created.

Parameters:

  • sequence Kiwi.Sequence

    The sequence that the Animation is based on.

  • [play=false] Boolean optional

    If the Animation should played once it has been created

Returns:

Kiwi.Animations.Animation:

The Animation that was created.

destroy

() public

Destroys the animation component and runs the destroy method on all of the anims that it has.

getAnimation

(
  • name
)
Kiwi.Animations.Animation public

Returns a Animation that is on this AnimationComponent Does not check to see if that Animation exists or not.

Parameters:

  • name String

    The name of the Animation you would like to get.

Returns:

Kiwi.Animations.Animation:

The Animation that is found. Will be 'undefined' if a Animation with that name did not exist.

nextFrame

() public

Makes the current animation go to the next frame. If the animation is at the end of the sequence it then goes back to the start.

objType

() String public

Returns a string indicating the type of object that this is.

Returns:

String:

"AnimationManager"

pause

() public

Pauses the current animation.

play

(
  • [name]
  • [resetTime=true]
)
Kiwi.Animations.Animation public

Plays either the current animation or the name of the animation that you pass.

Parameters:

  • [name] String optional

    The name of the animation that you want to play. If not passed it plays the current animation.

  • [resetTime=true] Boolean optional

    When set to false, this will prevent a new Animation from playing if it is already the currentAnimation that is already playing.

Returns:

Kiwi.Animations.Animation:

Returns the current Animation that is now playing.

playAt

(
  • index
  • [name]
)
Kiwi.Animations.Animation public

Plays an Animation at a particular frameIndex. Note: The frameIndex is a particular index of a cell in the Sequence of the Animation you would like to play. Example: If you had a Animation with a Sequence [0, 1, 2, 3] and you told it to play at index '2', then the cell that it would be at is '3'.

Parameters:

  • index Number

    The index of the frame in the Sequence that you would like to play.

  • [name] String optional

    The name of the animation that you want to play. If not passed, it attempts to play it on the current animation.

Returns:

Kiwi.Animations.Animation:

Returns the current Animation that is now playing.

postUpdate

() public

Components can postUpdate, that is run an update after the parent has updated. This is to be overriden by subclasses.

preUpdate

() public

Components can preUpdate, that is update before the parent updates. This is to be overriden by subclasses.

prevFrame

() public

Makes the current animation go to the prev frame. If the animation is at the start, the animation will go the end of the sequence.

resume

() public

Resumes the current animation. The animation should have already been paused.

stop

() public

Stops the current animation from playing.

switchTo

(
  • val
  • [play=null]
)
public

Either switches to a particular animation OR a particular frame in the current animation depending on if you pass the name of an animation that exists on this Manager (as a string) or a number refering to a frame index on the Animation. When you switch to a particular animation then You can also force the animation to play or to stop by passing a boolean in. But if left as null, the state of the Animation will based off what is currently happening. So if the animation is currently 'playing' then once switched to the animation will play. If not currently playing it will switch to and stop. If the previous animation played is non-looping and has reached its final frame, it is no longer considered playing, and as such, switching to another animation will not play unless the argument to the play parameter is true.

Parameters:

  • val String | Number
  • [play=null] Boolean optional

    Force the animation to play or stop. If null the animation base's it off what is currently happening.

update

() public

The update loop for this component. Only updates the currentAnimation and only if it is playing.

updateCellIndex

() protected

An internal method that is used to update the cell index of an entity when an animation says it needs to update.

Properties

_animations

Object private

A Object containing all of the animations that are avaiable to be used.

_atlas

Kiwi.Textures.TextureAtlas private

The texture atlas that this animation is taking effect on. The value of this should be the same as the Entity.

active

Boolean public

An active Component is one that has its update method called by its parent.

Default: true

currentAnimation

Kiwi.Animations.Animation public

A reference to the animation that is currently being played.

currentCell

Number public

Gets the cell that the current Animation is current at. This is READ ONLY.

dirty

Boolean deprecated public

The state of this component.

Default: false

entity

Kiwi.Entity public

The entity that this animation belongs to and thus is effecting.

frameIndex

Number public

Gets the current frame index of the cell in the Sequence that is currently playing. This is READ ONLY.

game

Kiwi.Game public

The game this Component belongs to

isPlaying

Boolean public

Returns a boolean indicating whether or not the current animation is playing. This is READ ONLY.

length

Number public

Returns the length (Number of cells) of the current Animation that is playing. This is READ ONLY.

name

String public

The name of this component.

onChange

Kiwi.Signal public

Dispatches callbacks each time the current animation is switched NOT when the cells of a animation change. Function's dispatched from this event have TWO parameters, One - Name of the animation switched to. Two - The Animation object that is now the current.

onPlay

Kiwi.Signal public

Dispatches callbacks each time an animation is told to play through this AnimationManager. Functions dispatched from this signal have ONE Parameter. One - The Animation object of that is now playing.

onStop

Kiwi.Signal public

Dispatches callbacks each time an animation stops. Functions dispatched from this signal have ONE parameter. One - The current animation.

onUpdate

Kiwi.Signal public

Dispatches callbacks each time the cell of the Sprite this AnimationManager belongs to updates/changes. Note: This method will be dispatching events EVERY time the cell changes, so this will include when changing/switching animations.

owner

Object public

The object that owns this entity

state

Kiwi.State public

Inherited from Kiwi.Component: src\core\Component.ts:56

Available since 1.3.1

The state which this component's owner belongs to.