Class Animation<T>
java.lang.Object
io.github.projectunified.craftux.animation.Animation<T>
- Type Parameters:
T- the frame type
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the frame based on the current timegetCurrentFrame(long currentMillis) Get the frame based on the current timeGet the framesbooleanCheck if it's the first run.booleanisFirstRun(long currentMillis) Check if it's the first run.voidreset()Reset the animation
-
Constructor Details
-
Animation
Creates a new Animation with the specified frames and period.- Parameters:
frames- the list of frames to cycle throughperiodMillis- the period in milliseconds between frame changesmode- the mode of the animation- Throws:
IllegalArgumentException- if frames is empty or periodMillis is not positive
-
Animation
Creates a new Animation with the specified frames and period.- Parameters:
frames- the list of frames to cycle throughperiodMillis- the period in milliseconds between frame changes- Throws:
IllegalArgumentException- if frames is empty or periodMillis is not positive
-
-
Method Details
-
getFrames
Get the frames- Returns:
- the frames
-
getCurrentFrame
Get the frame based on the current time- Parameters:
currentMillis- the current time in milliseconds- Returns:
- the frame
-
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
-