Class Animation

java.lang.Object
nl.colorize.multimedialib.stage.Animation

public class Animation extends Object
2D sprite animation that shows a number of images in sequence. Every frame in the animation is shown for a certain amount of time, indicated in seconds. After all images have been shown, the animation will either loop or keep showing the last image.

Note that this class *describes* the animation, it does not contain any state that relates to *showing* the animation. This allows for using the same animation data to display the animation multiple times simultaneously, but it does mean the animation's playback state needs to be managed by the user of this class.

  • Constructor Details

    • Animation

      public Animation(boolean loop)
    • Animation

      public Animation(List<Image> frames, float frameTime, boolean loop)
    • Animation

      public Animation(Image frame)
  • Method Details

    • addFrame

      public void addFrame(Image frame, float frameTime)
    • getFrameCount

      public int getFrameCount()
    • getFrameImages

      public List<Image> getFrameImages()
    • getFrameAtIndex

      public Image getFrameAtIndex(int index)
    • getFrameAtTime

      public Image getFrameAtTime(float time)
    • getDuration

      public float getDuration()
    • setFrameTime

      public void setFrameTime(int index, float frameTime)
      Changes the frame time for the frame located at the specified index.
    • setFrameTimes

      public void setFrameTimes(List<Float> frameTimes)
      Changes the frame time for all frames within this animation. The number of elements in the list needs to match the number of frames within this animation.
    • setFrameTime

      public void setFrameTime(float frameTime)
      Changes the frame time for all frames within this animation.
    • getFrameTime

      public float getFrameTime(int index)
    • isLoop

      public boolean isLoop()
    • copy

      public Animation copy()
    • reverse

      public Animation reverse()
      Returns a new animation with the same frames as this one, but with all frames and corresponding frame times in reverse compared to the original.
    • append

      public Animation append(Animation other)
      Returns a new animation that contains all frames of this animation followed by all frames of the specified other animation.
    • repeat

      public Animation repeat(int times)
      Returns a new animation with the same frames as this one, but repeated by the specified number of times.
      Throws:
      IllegalArgumentException - if the new animation does not repeat at least twice (since repeating once would be identical to the original animation.
    • mirror

      public Animation mirror()
      Returns a new animation with the same frames as this one, but appends the reversed version of the animation. For example, if the original animation consists of frames 1-2-3, the result would be 1-2-3-3-2-1.