Class SpriteAnimation

All Implemented Interfaces:
Mask

public class SpriteAnimation extends TextureBasedEntity<SpriteAnimation> implements Mask
A SpriteAnimation is a graphical entity which displays a sequence of images. You can use this class to animate a sprite based on milliseconds, rather than frame time.
  • Method Details

    • isPlaying

      public boolean isPlaying()
      Returns whether the animation is flagged to have the graphical counterpart play the animation or to pause it.

      Default is true.

      Returns:
      true if the animation is playing.
    • setPlaying

      public SpriteAnimation setPlaying(boolean playing)
      Plays or pause the animation.

      Default is playing (true).

      Parameters:
      playing - true to play animation, false to pause animation
      Returns:
      this animation.
    • reset

      public SpriteAnimation reset()
      Reset the progress of the animation
      Returns:
      this animation.
    • play

      public SpriteAnimation play()
      Calls setPlaying(true);
      Returns:
      this animation.
    • pause

      public SpriteAnimation pause()
      Calls setPlaying(false);
      Returns:
      this animation.
    • isLoop

      public boolean isLoop()
      Returns whether the animation should loop.

      Default is false.

      Returns:
      true if the animation loops.
    • setLoop

      public SpriteAnimation setLoop(boolean loop)
      Sets whether the animation loops. If false, the last image of the animation stays visible at the end.

      Default is false.

      Parameters:
      loop - true to make this animation loop.
      Returns:
      this animation.
    • getDuration

      public int getDuration()
      Returns the duration of the animation in milliseconds.

      Default is 1000.

      Returns:
      the duration of the animation in milliseconds.
    • setDuration

      public SpriteAnimation setDuration(int duration)
      Sets the duration of the animation in milliseconds.

      Default is 1000.

      Parameters:
      duration - the duration of the animation in milliseconds.
      Returns:
      this animation.
      Throws:
      IllegalArgumentException - if duration is negative.
    • setImages

      public SpriteAnimation setImages(String... images)
      Sets the sequence of images for this animation.
      Parameters:
      images - the names of the images to use for this animation.
      Returns:
      this animation.
      Throws:
      IllegalArgumentException - if images is empty.
    • getImages

      public String[] getImages()
      Returns the names of the images used for this animation.
      Returns:
      the names of the images used for this animation.