public class Animation
extends java.lang.Object
Texture
s displayed in rapid succession
to create the appearance of movement.
Animation objects are created using the load(String, int, int, double, boolean)
method.
Multiple instances of a Sprite
should not share a single Animation reference,
as each Sprite will require its own elapsedTime
field;
in this case, use the clone()
method to create a copy of the original Animation.Modifier and Type | Field and Description |
---|---|
Texture |
currentTexture
The texture that should be displayed by this animation,
according to the amount of time that has elapsed (
elapsedTime ). |
(package private) double |
elapsedTime
The amount of time that has elapsed since this animation began playing.
|
(package private) double |
frameDuration
The amount of time each texture should be displayed by this animation.
|
(package private) boolean |
loop
Determines if this animation should repeat after displaying the last texture in the list.
|
boolean |
paused
Determines if this animation should stop updating.
|
(package private) java.util.ArrayList<Texture> |
textureList
List of the textures that will be displayed in sequence by this animation.
|
(package private) double |
totalDuration
The total amount of time required to display all textures in this animation.
|
Constructor and Description |
---|
Animation()
Create an empty animation.
|
Modifier and Type | Method and Description |
---|---|
Animation |
clone() |
boolean |
isFinished()
Determines if this animation has finished playing.
|
static Animation |
load(java.lang.String imageFileName,
int rows,
int cols,
double frameDuration,
boolean loop)
Create an animation object from a sprite sheet.
|
void |
update(double dt)
Update
elapsedTime and currentTexture
based on the amount of time that has passed since last update. |
public Texture currentTexture
elapsedTime
).public boolean paused
java.util.ArrayList<Texture> textureList
double frameDuration
boolean loop
double elapsedTime
double totalDuration
Animation()
clone()
.public void update(double dt)
elapsedTime
and currentTexture
based on the amount of time that has passed since last update.dt
- amount of time that has passed since the last iteration of the game looppublic boolean isFinished()
public Animation clone()
clone
in class java.lang.Object
public static Animation load(java.lang.String imageFileName, int rows, int cols, double frameDuration, boolean loop)
imageFileName
- name of image filerows
- number of rows of individual images in filecols
- number of columns of individual images in fileframeDuration
- amount of time to display each individual imageloop
- whether this animation should repeat after last image is displayed