public class Animation extends java.lang.Object implements Animatable
An Animation is a sequence of one or more Animatable frames that may be instantiated in an AnimationInstance in order to be displayed one after another and/or smoothly transitioned between. The frames are indexed by the integers from 0 to getNumFrames() - 1 inclusive, and each has its own duration in fracunits. Durations of 0 or less are interpreted as infinite.
The frames of an Animation may be other Animations in addition to single Sprites, which allows for the creation of multi-dimensional Animations in a similar manner to multi-dimensional arrays.
In order to be of use, Animations need not represent linear progressions of frames; they may also be collections of counterpart Animations that need to be switched between without an AnimationInstance losing its place in them.
Once created, Animations are static and immutable, with all movement through time happening in AnimationInstances.
All of Animation's constructors treat a null Animatable as equivalent to Sprite.BLANK, and thus no frame of an Animation may be null.
Animatable
,
Sprite
Modifier and Type | Field and Description |
---|---|
static Animation |
BLANK
A blank Animation with Sprite.BLANK, duration 0, as its only frame.
|
Constructor and Description |
---|
Animation(Animatable... frames)
Constructs an Animation with the specified sequence of Animatable objects
as its frames.
|
Animation(Animatable frame)
Constructs an Animation with the specified Animatable object, duration 0,
as its only frame.
|
Animation(Animatable[] frames,
long... frameDurations)
Constructs an Animation out of the Animatable objects in the specified
array of frames.
|
Animation(SpriteSheet spriteSheet,
int x1,
int y1,
int x2,
int y2,
boolean columns)
Constructs an Animation with the Sprites in a rectangular region of a
SpriteSheet as its frames.
|
Animation(SpriteSheet spriteSheet,
int x1,
int y1,
int x2,
int y2,
boolean columns,
long... frameDurations)
Constructs an Animation with the Sprites in a rectangular region of a
SpriteSheet as its frames.
|
Modifier and Type | Method and Description |
---|---|
boolean |
framesAreCompatible(int index1,
int index2)
Returns whether the two frames at the specified indices are compatible
for AnimationInstances' transitioning purposes.
|
Animation |
getFilteredCopy(Filter filter,
boolean load)
Returns a new Animatable created by applying a Filter to all of the
Sprites of which this Animatable is ultimately composed.
|
Animatable |
getFrame(int index)
Returns this Animatable's frame at the specified index.
|
long |
getFrameDuration(int index)
Returns the duration in fracunits of this Animatable's frame at the
specified index.
|
Drawable |
getInstance()
Returns a Drawable instantiation of this Animation - that is, a new
AnimationInstance of this Animation, with its indices and speeds at each
level starting at 0.
|
int |
getLevel()
Returns how many levels of Animations this Animatable and its frames and
sub-frames comprise.
|
int |
getNumFrames()
Returns how many frames this Animatable has.
|
java.util.Set<Sprite> |
getSprites()
Returns an unmodifiable Set view of all of the Sprites that ultimately
compose this Animatable.
|
public static final Animation BLANK
public Animation(Animatable frame)
frame
- The Animatable object out of which to make the Animationpublic Animation(Animatable... frames)
frames
- The sequence of the Animation's framespublic Animation(Animatable[] frames, long... frameDurations)
frames
- The array of the Animation's framesframeDurations
- The sequence of the Animation's frame durations in
fracunitspublic Animation(SpriteSheet spriteSheet, int x1, int y1, int x2, int y2, boolean columns)
spriteSheet
- The SpriteSheet out of which to make the Animationx1
- The x-coordinate, in Sprites, of the region's left edgey1
- The y-coordinate, in Sprites, of the region's top edgex2
- The x-coordinate, in Sprites, of the region's right edgey2
- The y-coordinate, in Sprites, of the region's bottom edgecolumns
- If true, the Sprites will be read from the SpriteSheet in
columns from top to bottom, the columns going from left to right.
Otherwise, they will be read in rows from left to right, the rows going
from top to bottom. The Sprites will appear in the Animation in the order
in which they are read.public Animation(SpriteSheet spriteSheet, int x1, int y1, int x2, int y2, boolean columns, long... frameDurations)
spriteSheet
- The SpriteSheet out of which to make the Animationx1
- The x-coordinate, in Sprites, of the region's left edgey1
- The y-coordinate, in Sprites, of the region's top edgex2
- The x-coordinate, in Sprites, of the region's right edgey2
- The y-coordinate, in Sprites, of the region's bottom edgecolumns
- If true, the Sprites will be read from the SpriteSheet in
columns from top to bottom, the columns going from left to right.
Otherwise, they will be read in rows from left to right, the rows going
from top to bottom. The Sprites will appear in the Animation in the order
in which they are read.frameDurations
- The sequence of the Animation's frame durationspublic final int getLevel()
Animatable
getLevel
in interface Animatable
public final int getNumFrames()
Animatable
getNumFrames
in interface Animatable
public final Animatable getFrame(int index)
Animatable
getFrame
in interface Animatable
index
- The index of the frame to be returnedpublic final long getFrameDuration(int index)
Animatable
getFrameDuration
in interface Animatable
index
- The index of the frame whose duration is to be returnedpublic final boolean framesAreCompatible(int index1, int index2)
Animatable
framesAreCompatible
in interface Animatable
index1
- The index of the first frameindex2
- The index of the second framepublic final java.util.Set<Sprite> getSprites()
Animatable
getSprites
in interface Animatable
public final Animation getFilteredCopy(Filter filter, boolean load)
Animatable
getFilteredCopy
in interface Animatable
filter
- The Filter to apply to this Animatable's Sprites to create
the new Animatableload
- Whether the new Animatable should load its Sprites upon its
creationpublic final Drawable getInstance()
getInstance
in interface Animatable