Scratch for Java

AnimatedSprite::resetAnimation()

Resets an animation. This is useful for example, when an animation should only be played once, but maybe on a user interaction should play again.

Examples

import org.openpatch.scratch.*;
import org.openpatch.scratch.extensions.animation.*;
 
public class AnimatedSpriteResetAnimation {
  public AnimatedSpriteResetAnimation() {
    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(4000)) {
      bee.playAnimation("idle", true);
      if (myStage.isKeyPressed(KeyCode.VK_SPACE)) {
        bee.resetAnimation();
      }
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new AnimatedSpriteResetAnimation();
  }
}
 

View on GitHub

Syntax

Java

.resetAnimation()

Scratch

reset animation

Return

void

resetAnimation()