Scratch for Java

AnimatedSprite::playAnimation()

Plays an animation.

Examples

import org.openpatch.scratch.*;
import org.openpatch.scratch.extensions.animation.*;
 
public class AnimatedSpritePlayAnimation {
  public AnimatedSpritePlayAnimation() {
    Stage myStage = new Stage(600, 240);
    AnimatedSprite bee = new AnimatedSprite();
    bee.addAnimation("idle", "assets/bee_idle.png", 6, 36, 34);
    myStage.add(bee);
    bee.changeX(-30);
 
    AnimatedSprite bee2 = new AnimatedSprite();
    bee2.addAnimation("idle", "assets/bee_idle.png", 6, 36, 34);
    myStage.add(bee2);
    bee2.changeX(30);
 
    while (myStage.getTimer().forMillis(3000)) {
      bee.playAnimation("idle", true);
      bee2.playAnimation("idle");
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new AnimatedSpritePlayAnimation();
  }
}
 

View on GitHub

Syntax

Java

.playAnimation(name)
.playAnimation(name, once)

Scratch

play animation (name)

Parameters

Name Data Type Description
name String The name of the animation to play
once boolean If true plays the animation only once.

Return

void

playAnimation()