Constructor
new SpriteAnimation(tileInfo, frameCount, frameTimeopt)
Create an animation over a run of frames, looping from the start
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
tileInfo | TileInfo | The first frame | ||
frameCount | number | How many frames, one or more | ||
frameTime | number | <optional> | 0.1 | Seconds each frame shows for |
- Source
const walk = new SpriteAnimation(tile(0, 16), 4, .1); // four frames, a tenth of a second each
const attack = new SpriteAnimation(tile(4, 16), 3, .05).play(); // once, then holds the last frame
// in update: this.tileInfo = (attack.isDone ? walk : attack).tileInfo;Members
elapsedFrames
How many frames have gone by since the start, fractional
- Source
firstTile
Properties| Type | Description |
|---|---|
| TileInfo | The first frame, the others follow it along the row |
- Source
frame
The frame showing now, 0 to frameCount-1
- Source
frameCount
Properties| Type | Description |
|---|---|
| number | How many frames |
- Source
frameTime
Properties| Type | Description |
|---|---|
| number | Seconds each frame shows for |
- Source
heldFrame :number|undefined
- number |
undefined
| Type | Description |
|---|---|
| number | | The frame held by stop, undefined while running |
- Source
isDone
True once a play has shown its last frame for its time
- Source
mode
Properties| Type | Description |
|---|---|
| string | How it runs: 'loop', 'once' or 'pingPong', set by loop, play and pingPong |
- Source
speed
Properties| Type | Description |
|---|---|
| number | Rate multiplier, 2 plays twice as fast; set it before starting |
- Source
startTime
Properties| Type | Description |
|---|---|
| number | Engine time it started at |
- Source
tileInfo
The tile of the frame showing now
- Source
Methods
loop() → {SpriteAnimation}
Start over from the first frame and repeat forever
- Source
- Type:
- SpriteAnimation
pingPong() → {SpriteAnimation}
Start over from the first frame and run there and back forever
- Source
- Type:
- SpriteAnimation
play() → {SpriteAnimation}
Start over from the first frame, run through once and hold the last frame
- Source
- Type:
- SpriteAnimation
restart(modeopt) → {SpriteAnimation}
Start over from the first frame in a mode
| Name | Type | Attributes | Description |
|---|---|---|---|
mode | string | <optional> | 'loop', 'once' or 'pingPong', the current mode when left out |
- Source
- Type:
- SpriteAnimation
stop() → {SpriteAnimation}
Hold the current frame
- Source
- Type:
- SpriteAnimation