Scratch for Java

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.*;
import org.openpatch.scratch.extensions.animation.*;

public class AnimatedSpriteAddAnimation {
  public AnimatedSpriteAddAnimation() {
    Stage myStage = new Stage(600, 240);
    AnimatedSprite bee = new AnimatedSprite();
    bee.addAnimation("idle", "assets/bee_idle.png", 6, 36, 34);
    myStage.add(bee);

    while (myStage.getTimer().forMillis(5000)) {
      bee.playAnimation("idle");
    }
    myStage.exit();
  }

  public static void main(String[] args) {
    new AnimatedSpriteAddAnimation();
  }
}

View on GitHub

Syntax

Java

.addAnimation(name, pattern, frames)
.addAnimation(name, path, frames, width, height)
.addAnimation(name, path, frames, width, height, row)

Scratch

Parameters

NameData TypeDescription
nameStringName of the animation
patternStringA pattern for finding images representing the frames.
framesintThe number of frames for this animation.
widthintThe width of one frame. Only needed when loading from a spritesheet.
heightintThe height of one frame. Only needed when loading from a spritesheet.
rowintThe row in a spritesheet. Only needed when loading from a spritesheet.

Return

void