Sprite::addAnimation()
Adds an animation from numbered image files: the pattern's %d counts from 1.
this.addAnimation("walk", "assets/walk%d.png", 4); // walk1.png \u2026 walk4.png
this.addAnimation("hit", "assets/hit%d.png", 0, 4); // hit0.png \u2026 hit4.png
this.addAnimation("walk", "assets/walk.png", 32, 32, 0, 1, 2, 3); // the first row
this.addAnimation("down", "assets/hero.png", 32, 32, 0, 4, 8, 12); // the first column of 4
Syntax
Java
.addAnimation(name, pattern, frames)
.addAnimation(name, pattern, from, to)
.addAnimation(name, sheetPath, width, height, frames)
Parameters
| Name | Data Type | Description |
|---|---|---|
| name | String | the animation's name |
| pattern | String | the file names, with `%d` for the frame number |
| frames | int | how many frames |
| from | int | the number of the first frame |
| to | int | the number of the last frame |
| sheetPath | String | the sprite sheet |
| width | int | the width of a frame |
| height | int | the height of a frame |
Return
void