AnimatedSprite::addAnimation()
Add an animation to the sprite. The animation can either be multiple images or parts of a spritesheet.
Examples

import org.openpatch.scratch.extensions.animation.AnimatedSprite;
public class MySprite extends AnimatedSprite {
public MySprite() {
this.addAnimation("idle", "assets/bee_idle.png", 6, 36, 34);
}
public void run() {
this.playAnimation("idle");
}
}
import org.openpatch.scratch.Stage;
public class MyStage extends Stage {
public MyStage() {
this.add(new MySprite());
}
}
import org.openpatch.scratch.Stage;
import org.openpatch.scratch.Window;
public class MyWindow extends Window {
public MyWindow() {
Stage myStage = new MyStage();
this.setStage(myStage);
// Wait for 5 seconds
while (myStage.getTimer().forMillis(5000))
;
this.exit();
}
public static void main(String[] args) {
new MyWindow();
}
}
Syntax
Java
.addAnimation(name, pattern, frames)
.addAnimation(name, path, frames, width, height)
.addAnimation(name, path, frames, width, height, row)
Scratch
add animation (name) (pattern) (frames)
Parameters
Name | Data Type | Description |
---|---|---|
name | String | Name of the animation |
pattern | String | A pattern for finding images representing the frames. |
frames | int | The number of frames for this animation. |
width | int | The width of one frame. Only needed when loading from a spritesheet. |
height | int | The height of one frame. Only needed when loading from a spritesheet. |
row | int | The row in a spritesheet. Only needed when loading from a spritesheet. |
Return
void