public class AnimationInstance extends java.lang.Object implements Drawable
An AnimationInstance is an instance of an Animation that represents a point in the Animation and rates at which that point progresses through the Animation. An AnimationInstance has one level for each dimension of its Animation, numbered 0 through the number of dimensions minus 1 inclusive. For example, an instance of a level 2 Animation (an Animation of Animations) has two levels: level 0 for the component Animations, and level 1 for the Animation of Animations.
At each of its levels, an AnimationInstance has an index of its current position in that level of the Animation, as well as a speed that represents how fast, in frame duration units per time unit, it advances through that level. If a level's speed is negative, the AnimationInstance will cycle through the Animation at that level backward. If an AnimationInstance moves forward past a level's end or backward past its beginning, it will loop back to the beginning or end, respectively.
When an AnimationInstance is drawn, it will appear as the Sprite in its Animation that its current indices specify. The Filters that can be successfully applied to that Sprite when it is drawn through the AnimationInstance are the same ones as when the Sprite is drawn by itself.
AnimationInstances keep track of time by being added to one CellGameState each. An AnimationInstance's time factor represents how many time units the AnimationInstance will experience every frame while assigned to an active CellGameState. If its own time factor is negative, an AnimationInstance will use its assigned CellGameState's time factor instead. If an AnimationInstance is assigned to an inactive CellGameState or none at all, time will not pass for it. AnimationInstances assigned to the active CellGameState update their indices at the beginning of each frame, before Thinkers' timeUnitActions() are taken.
Modifier and Type | Field and Description |
---|---|
static AnimationInstance |
BLANK
A blank AnimationInstance of Animation.BLANK.
|
Constructor and Description |
---|
AnimationInstance(Animation animation)
Creates a new AnimationInstance of the specified Animation.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(org.newdawn.slick.Graphics g,
int x,
int y)
Draws this Drawable to the specified Graphics context.
|
void |
draw(org.newdawn.slick.Graphics g,
int x,
int y,
boolean xFlip,
boolean yFlip,
double angle,
double alpha,
Filter filter)
Draws this Drawable to the specified Graphics context.
|
void |
draw(org.newdawn.slick.Graphics g,
int x,
int y,
double scale,
boolean xFlip,
boolean yFlip,
double alpha,
Filter filter)
Draws this Drawable to the specified Graphics context.
|
void |
draw(org.newdawn.slick.Graphics g,
int x,
int y,
int left,
int right,
int top,
int bottom)
Draws a rectangular region of this Drawable to the specified Graphics
context.
|
void |
draw(org.newdawn.slick.Graphics g,
int x,
int y,
int left,
int right,
int top,
int bottom,
boolean xFlip,
boolean yFlip,
double angle,
double alpha,
Filter filter)
Draws a rectangular region of this Drawable to the specified Graphics
context.
|
void |
draw(org.newdawn.slick.Graphics g,
int x,
int y,
int left,
int right,
int top,
int bottom,
double scale,
boolean xFlip,
boolean yFlip,
double alpha,
Filter filter)
Draws a rectangular region of this Drawable to the specified Graphics
context.
|
Animation |
getAnimation()
Returns the Animation that this AnimationInstance is an instance of.
|
Sprite |
getCurrentSprite()
Returns the Sprite that is specified by this AnimationInstance's current
indices, and that the draw() methods will draw if called now.
|
double |
getEffectiveTimeFactor()
Returns this AnimationInstance's effective time factor; that is, how many
time units it experiences every frame.
|
CellGameState |
getGameState()
Returns the CellGameState to which this AnimationInstance is currently
assigned, or null if it is assigned to none.
|
int |
getIndex()
Returns this AnimationInstance's current index at its highest level.
|
int |
getIndex(int level)
Returns this AnimationInstance's current index at the specified level.
|
double |
getSpeed()
Returns this AnimationInstance's speed at its highest level.
|
double |
getSpeed(int level)
Returns this AnimationInstance's speed at the specified level.
|
double |
getTimeFactor()
Returns this AnimationInstance's time factor.
|
void |
setGameState(CellGameState state)
Sets the CellGameState to which this AnimationInstance is currently
assigned.
|
void |
setIndex(int index)
Sets this AnimationInstance's index at its highest level to the specified
value.
|
void |
setIndex(int level,
int index)
Sets this AnimationInstance's index at the specified level to the
specified value.
|
void |
setIndex(int level,
int index,
boolean resetLowerIndices)
Sets this AnimationInstance's index at the specified level to the
specified value.
|
void |
setSpeed(double speed)
Sets this AnimationInstance's speed at its highest level to the specified
value.
|
void |
setSpeed(int level,
double speed)
Sets this AnimationInstance's speed at the specified level to the
specified value.
|
void |
setTimeFactor(double timeFactor)
Sets this AnimationInstance's time factor to the specified value.
|
public static final AnimationInstance BLANK
public AnimationInstance(Animation animation)
animation
- The animation to make the AnimationInstance ofpublic final Sprite getCurrentSprite()
public final CellGameState getGameState()
public final void setGameState(CellGameState state)
state
- The CellGameState to which this AnimationInstance should be
assignedpublic final double getTimeFactor()
public final double getEffectiveTimeFactor()
public final void setTimeFactor(double timeFactor)
timeFactor
- The new time factorpublic final Animation getAnimation()
public final int getIndex()
public final int getIndex(int level)
level
- The level of the index to be returnedpublic final void setIndex(int index)
index
- The value to which the index will be setpublic final void setIndex(int level, int index)
level
- The level of the index to be setindex
- The value to which the index will be setpublic final void setIndex(int level, int index, boolean resetLowerIndices)
level
- The level of the index to be setindex
- The value to which the index will be setresetLowerIndices
- If this is false and the frame at the new index
is compatible with the frame at the current one, the indices at lower
levels will not be reset to 0. Otherwise, they will be.public final double getSpeed()
public final double getSpeed(int level)
level
- The level of the speed to be returnedpublic final void setSpeed(double speed)
speed
- The value to which the speed will be setpublic final void setSpeed(int level, double speed)
level
- The level of the speed to be setspeed
- The value to which the speed will be setpublic final void draw(org.newdawn.slick.Graphics g, int x, int y)
Drawable
public final void draw(org.newdawn.slick.Graphics g, int x, int y, boolean xFlip, boolean yFlip, double angle, double alpha, Filter filter)
Drawable
draw
in interface Drawable
g
- The Graphics context to draw this Drawable tox
- The x-coordinate on the Graphics context of the originy
- The y-coordinate on the Graphics context of the originxFlip
- If true, the drawn image is flipped along a vertical line
through the originyFlip
- If true, the drawn image is flipped along a horizontal line
through the originangle
- The angle in degrees by which to rotate the drawn image and
its xFlip and yFlip lines counterclockwise around the originalpha
- The drawn image's alpha (opacity) value from 0 to 1filter
- The Filter to apply to the drawn image, or null if none
should be applied. Not every Filter has an effect on every Drawable.public final void draw(org.newdawn.slick.Graphics g, int x, int y, double scale, boolean xFlip, boolean yFlip, double alpha, Filter filter)
Drawable
draw
in interface Drawable
g
- The Graphics context to draw this Drawable tox
- The x-coordinate on the Graphics context of the originy
- The y-coordinate on the Graphics context of the originscale
- The factor by which to scale the drawn image around the
originxFlip
- If true, the drawn image is flipped along a vertical line
through the originyFlip
- If true, the drawn image is flipped along a horizontal line
through the originalpha
- The drawn image's alpha (opacity) value from 0 to 1filter
- The Filter to apply to the drawn image, or null if none
should be applied. Not every Filter has an effect on every Drawable.public final void draw(org.newdawn.slick.Graphics g, int x, int y, int left, int right, int top, int bottom)
Drawable
draw
in interface Drawable
g
- The Graphics context to draw this Drawable tox
- The x-coordinate on the Graphics context of the originy
- The y-coordinate on the Graphics context of the originleft
- The x-coordinate on the image, relative to the origin, of the
drawn region's left edgeright
- The x-coordinate on the image, relative to the origin, of
the drawn region's right edgetop
- The y-coordinate on the image, relative to the origin, of the
drawn region's top edgebottom
- The y-coordinate on the image, relative to the origin, of
the drawn region's bottom edgepublic final void draw(org.newdawn.slick.Graphics g, int x, int y, int left, int right, int top, int bottom, boolean xFlip, boolean yFlip, double angle, double alpha, Filter filter)
Drawable
draw
in interface Drawable
g
- The Graphics context to draw this Drawable tox
- The x-coordinate on the Graphics context of the originy
- The y-coordinate on the Graphics context of the originleft
- The x-coordinate on the image, relative to the origin, of the
drawn region's left edgeright
- The x-coordinate on the image, relative to the origin, of
the drawn region's right edgetop
- The y-coordinate on the image, relative to the origin, of the
drawn region's top edgebottom
- The y-coordinate on the image, relative to the origin, of
the drawn region's bottom edgexFlip
- If true, the drawn region is flipped along a vertical line
through the image's originyFlip
- If true, the drawn region is flipped along a horizontal line
through the image's originangle
- The angle in degrees by which to rotate the drawn region and
its xFlip and yFlip lines counterclockwise around the image's originalpha
- The drawn region's alpha (opacity) value from 0 to 1filter
- The Filter to apply to the drawn region, or null if none
should be applied. Not every Filter has an effect on every Drawable.public final void draw(org.newdawn.slick.Graphics g, int x, int y, int left, int right, int top, int bottom, double scale, boolean xFlip, boolean yFlip, double alpha, Filter filter)
Drawable
draw
in interface Drawable
g
- The Graphics context to draw this Drawable tox
- The x-coordinate on the Graphics context of the originy
- The y-coordinate on the Graphics context of the originleft
- The x-coordinate on the image, relative to the origin, of the
drawn region's left edgeright
- The x-coordinate on the image, relative to the origin, of
the drawn region's right edgetop
- The y-coordinate on the image, relative to the origin, of the
drawn region's top edgebottom
- The y-coordinate on the image, relative to the origin, of
the drawn region's bottom edgescale
- The factor by which to scale the drawn region around the
originxFlip
- If true, the drawn region is flipped along a vertical line
through the image's originyFlip
- If true, the drawn region is flipped along a horizontal line
through the image's originalpha
- The drawn region's alpha (opacity) value from 0 to 1filter
- The Filter to apply to the drawn region, or null if none
should be applied. Not every Filter has an effect on every Drawable.