Class Animation
java.lang.Object
cit244.api.image.Animation
An immutable sequence of sprite frames played at a fixed frame rate.
Animations contain no playback state. The frameAt(double)
method selects a sprite using elapsed time relative to the beginning
of the animation.
For a looping animation synchronized with the sketch's clock:
Sprite pose = walk.frameAt(f.time());
For animations that start, stop, or switch in response to events,
use AnimationPlayer.
One-shot animations hold their last frame after finishing. Multiple objects can share the same animation.
-
Method Summary
Modifier and TypeMethodDescriptiondoubleduration()Returns the time required to display all frames once.frameAt(double seconds) Selects the sprite displayed at an animation-relative time.static AnimationCreates an animation that repeats after its last frame.static AnimationCreates an animation that holds its final frame when finished.
-
Method Details
-
loop
Creates an animation that repeats after its last frame.- Parameters:
fps- frames per second (positive)frames- sprite frames in playback order; at least one is required- Returns:
- a looping animation
- Throws:
IllegalArgumentException- if fps or the frame list is invalid
-
once
Creates an animation that holds its final frame when finished.- Parameters:
fps- frames per second (positive)frames- sprite frames in playback order; at least one is required- Returns:
- a non-looping animation
- Throws:
IllegalArgumentException- if fps or the frame list is invalid
-
duration
public double duration()Returns the time required to display all frames once.- Returns:
- one cycle's duration in seconds
-
frameAt
Selects the sprite displayed at an animation-relative time.For looping animations, time wraps around after each cycle. For one-shot animations, the final frame remains selected after
duration(). Negative times select the first frame.This method does NOT track time or restart the animation!! For animation switching and event-triggered playback, use
AnimationPlayer.- Parameters:
seconds- seconds elapsed since the animation began- Returns:
- sprite displayed at the given time
- Throws:
IllegalArgumentException- if seconds is NaN or infinite
-