Class AnimatedSprite

java.lang.Object
org.openpatch.scratch.Sprite
org.openpatch.scratch.extensions.animation.AnimatedSprite

public class AnimatedSprite extends Sprite
The AnimatedSprite class represents a sprite that can play animations. It extends the Sprite class and provides methods to add animations, play animations, set the interval between animation frames, and reset the animation.

Example usage:


 AnimatedSprite sprite = new AnimatedSprite();
 sprite.addCostume("idle", "assets/idle.png");
 sprite.addAnimation("walk", "assets/walk_%d.png", 4);
 sprite.playAnimation("walk");
 
See Also:
  • Constructor Details

    • AnimatedSprite

      public AnimatedSprite()
  • Method Details

    • addAnimation

      public void addAnimation(String name, String pattern, int frames)
      Adds an animation to the sprite.
      Parameters:
      name - the name of the animation
      pattern - the pattern (@see String#format) of the file names
      frames - the number of frames in the animation
    • addAnimation

      public void addAnimation(String name, String path, int frames, int width, int height)
      Adds an animation to the sprite.
      Parameters:
      name - the name of the animation
      path - the path to the animation frames
      frames - the number of frames in the animation
      width - the width of each frame
      height - the height of each frame
    • addAnimation

      public void addAnimation(String name, String path, int frames, int width, int height, int row)
      Adds an animation to the sprite.
      Parameters:
      name - the name of the animation
      path - the path to the animation frames
      frames - the number of frames in the animation
      width - the width of each frame
      height - the height of each frame
      row - the row of the animation frames
    • addAnimation

      public void addAnimation(String name, String path, int frames, int width, int height, int column, boolean useColumns)
      Adds an animation to the sprite.
      Parameters:
      name - the name of the animation
      path - the path to the animation frames
      frames - the number of frames in the animation
      width - the width of each frame
      height - the height of each frame
      column - the column of the animation frames
      useColumns - whether to use columns or rows
    • playAnimation

      public void playAnimation(String name)
      Plays the animation with the specified name.
      Parameters:
      name - the name of the animation to play
    • playAnimation

      public void playAnimation(String name, boolean once)
      Plays the animation with the specified name.
      Parameters:
      name - the name of the animation to play
      once - whether to play the animation once
    • resetAnimation

      public void resetAnimation()
      Resets the animation. The animation will start from the first frame.
    • setAnimationInterval

      public void setAnimationInterval(int interval)
      Sets the interval between animation frames.
      Parameters:
      interval - the interval between animation frames
    • getAnimationInterval

      public int getAnimationInterval()
      Gets the interval between animation frames.
      Returns:
      the interval between animation frames
    • getAnimationFrame

      public int getAnimationFrame()
      Gets the current animation frame.
      Returns:
      the current animation frame
    • setAnimationFrame

      public void setAnimationFrame(int frame)
      Sets the current animation frame.
      Parameters:
      frame - the current animation frame
    • isAnimationPlayed

      public boolean isAnimationPlayed()
      Checks if the animation is played.
      Returns:
      true if the animation is played, false otherwise