Skip to main content

Animations.js

Animations

A class to manage the animations of a sprite

Kind: global class
Constructors:

new Animations(parent, name, startFrame, numberOfFrames, [speed], [loop])

ParamTypeDescription
parentImpacto.GameObjects.Sprite

The parent Sprite.

namestring

The name of the Animations.

startFramenumber

The first frame of the Animations.

numberOfFramesnumber

Number of frames of the Animations.

[speed]number

The speed of the Animations.

[loop]boolean

Whether the Animations should loop or not.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth(), 0, 10, false);

Animations.get(name) ⇒ Animation

Returns the animation state

Kind: static method of Animations
Returns: Animation -

The animation state

ParamTypeDescription
namestring

The name of the Animation.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth(), 0, 10, false);
console.log(mySprite.animations.get(""Default""));

Animations.add(name, numberOfFrames, [startFrame], [speed], [loop])

Add a new animation to the sprite

Kind: static method of Animations

ParamTypeDefaultDescription
namestring

The name of the Animation.

numberOfFramesnumber

Number of frames of the Animation.

[startFrame]number0

The first frame of the Animation.

[speed]number100

The speed of the Animation.

[loop]booleantrue

Whether the Animation should loop or not.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth(), 0, 10, false);

Animations.getAnimationsNames() ⇒ Array.<string>

Returns all animations names

Kind: static method of Animations
Returns: Array.<string> -

The names of the animations


Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth());
console.log(mySprite.animations.getAnimationsNames());

Animations.reset() ⇒ Animation

Reset the animation

Kind: static method of Animations
Returns: Animation -

The animation state


Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).reset();

Animations.play(name) ⇒ Animation

Play the animation

Kind: static method of Animations
Returns: Animation -

The animation state

ParamTypeDescription
namestring

The name of the Animation.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).play("Default");

Animations.pause() ⇒ Animation

Pause the animation

Kind: static method of Animations
Returns: Animation -

The animation state


Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).pause();

Animations.resume() ⇒ Animation

Resume the animation

Kind: static method of Animations
Returns: Animation -

The animation state


Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).resume();

Animations.setName(oldName, newName) ⇒ Animation

Change the name of a animation

Kind: static method of Animations
Returns: Animation -

The animation state

ParamTypeDescription
oldNamestring

The name of the Animation.

newNamestring

The new name of the Animation.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).changeName("NewName");

Animations.setSpeed(name, speed) ⇒ Animation

Change the speed of a animation

Kind: static method of Animations
Returns: Animation -

The animation state

ParamTypeDescription
namestring

The name of the Animation.

speednumber

The new speed of the Animation.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).changeSpeed(100);

Animations.setNumberOfFrames(name, numberOfFrames) ⇒ Animation

Change the number of frame of a animation

Kind: static method of Animations
Returns: Animation -

The animation state

ParamTypeDescription
namestring

The name of the Animation.

numberOfFramesnumber

The new number of frames of the Animation.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).changeNumberOfFrames(10);

Animations.setLoop(name, loop) ⇒ Animation

Change if animation if in loop or not

Kind: static method of Animations
Returns: Animation -

The animation state

ParamTypeDescription
namestring

The name of the Animation.

loopboolean

The new loop state of the Animation.

Example

const mySprite = new Impacto.GameObjects.Sprite(400, 300, "MySprite");
mySprite.animations.add("Default", mySprite.getNumFramesByWidth()).changeLoop(false);