Animations.js
Animations
A class to manage the animations of a sprite
Kind: global class
Constructors:
- Animations
- new Animations(parent, name, startFrame, numberOfFrames, [speed], [loop])
- .get(name) ⇒
Animation
- .add(name, numberOfFrames, [startFrame], [speed], [loop])
- .getAnimationsNames() ⇒
Array.<string>
- .reset() ⇒
Animation
- .play(name) ⇒
Animation
- .pause() ⇒
Animation
- .resume() ⇒
Animation
- .setName(oldName, newName) ⇒
Animation
- .setSpeed(name, speed) ⇒
Animation
- .setNumberOfFrames(name, numberOfFrames) ⇒
Animation
- .setLoop(name, loop) ⇒
Animation
new Animations(parent, name, startFrame, numberOfFrames, [speed], [loop])
Param | Type | Description |
---|---|---|
parent | Impacto.GameObjects.Sprite | The parent Sprite. |
name | string | The name of the Animations. |
startFrame | number | The first frame of the Animations. |
numberOfFrames | number | 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
Param | Type | Description |
---|---|---|
name | string | 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
Param | Type | Default | Description |
---|---|---|---|
name | string | The name of the Animation. | |
numberOfFrames | number | Number of frames of the Animation. | |
[startFrame] | number | 0 | The first frame of the Animation. |
[speed] | number | 100 | The speed of the Animation. |
[loop] | boolean | true | 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
Param | Type | Description |
---|---|---|
name | string | 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
Param | Type | Description |
---|---|---|
oldName | string | The name of the Animation. |
newName | string | 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
Param | Type | Description |
---|---|---|
name | string | The name of the Animation. |
speed | number | 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
Param | Type | Description |
---|---|---|
name | string | The name of the Animation. |
numberOfFrames | number | 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
Param | Type | Description |
---|---|---|
name | string | The name of the Animation. |
loop | boolean | 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);