Class Animation<T>

java.lang.Object
io.github.projectunified.craftux.animation.Animation<T>
Type Parameters:
T - the frame type

public class Animation<T> extends Object
Manages a sequence of frames that cycle over time with a specified period. Provides methods to get the current frame based on elapsed time and reset the animation.

Example usage:


 List<String> frames = Arrays.asList("Frame1", "Frame2", "Frame3");
 Animation<String> animation = new Animation<>(frames, 1000); // 1 second per frame
 String current = animation.getCurrentFrame(); // Gets current frame based on time
 
  • Constructor Details

    • Animation

      public Animation(List<T> frames, long periodMillis, AnimationMode mode)
      Creates a new Animation with the specified frames and period.
      Parameters:
      frames - the list of frames to cycle through
      periodMillis - the period in milliseconds between frame changes
      mode - the mode of the animation
      Throws:
      IllegalArgumentException - if frames is empty or periodMillis is not positive
    • Animation

      public Animation(List<T> frames, long periodMillis)
      Creates a new Animation with the specified frames and period.
      Parameters:
      frames - the list of frames to cycle through
      periodMillis - the period in milliseconds between frame changes
      Throws:
      IllegalArgumentException - if frames is empty or periodMillis is not positive
  • Method Details

    • getFrames

      public List<T> getFrames()
      Get the frames
      Returns:
      the frames
    • getCurrentFrame

      public T getCurrentFrame(long currentMillis)
      Get the frame based on the current time
      Parameters:
      currentMillis - the current time in milliseconds
      Returns:
      the frame
    • getCurrentFrame

      public T getCurrentFrame()
      Get the frame based on the current time
      Returns:
      the frame
    • reset

      public void reset()
      Reset the animation
    • isFirstRun

      public boolean isFirstRun(long currentMillis)
      Check if it's the first run. It will return true if the animation is running for the first time.
      Parameters:
      currentMillis - the current time in milliseconds
      Returns:
      true if it's the first run
    • isFirstRun

      public boolean isFirstRun()
      Check if it's the first run. It will return true if the animation is running for the first time.
      Returns:
      true if it's the first run