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 fracunits per GameState time unit, it advances through that level. Each level's index and speed are both initially 0. 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 assigned to one GameState each. An AnimationInstance's time factor represents the average number of discrete time units the AnimationInstance will experience every frame while assigned to an active GameState. If its own time factor is negative, as it is by default, an AnimationInstance will use its assigned GameState's time factor instead. If an AnimationInstance is assigned to an inactive GameState or none at all, time will not pass for it. AnimationInstances assigned to the active GameState update their indices at the beginning of each frame, before Thinkers' timer values are updated.
All operations on an AnimationInstance return the AnimationInstance itself to allow operations to be easily strung together.
GameState
Modifier and Type | Field and Description |
---|---|
static AnimationInstance |
BLANK
A blank AnimationInstance of Animation.BLANK.
|
Constructor and Description |
---|
AnimationInstance(Animation animation)
Constructs an AnimationInstance of the specified Animation.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(Graphics g,
int x,
int y)
Draws this Drawable's image to the specified Graphics context.
|
void |
draw(Graphics g,
int x,
int y,
boolean xFlip,
boolean yFlip,
double angle,
double alpha,
Filter filter)
Draws this Drawable's image to the specified Graphics context.
|
void |
draw(Graphics g,
int x,
int y,
double scale,
boolean xFlip,
boolean yFlip,
double alpha,
Filter filter)
Draws this Drawable's image to the specified Graphics context.
|
void |
draw(Graphics g,
int x,
int y,
int left,
int right,
int top,
int bottom)
Draws a rectangular region of this Drawable's image to the specified
Graphics context.
|
void |
draw(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's image to the specified
Graphics context.
|
void |
draw(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's image 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.
|
long |
getEffectiveTimeFactor()
Returns this AnimationInstance's effective time factor; that is, the
average number of time units it experiences every frame.
|
GameState |
getGameState()
Returns the GameState to which this AnimationInstance is assigned, or
null if it is not assigned to one.
|
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.
|
long |
getSpeed()
Returns this AnimationInstance's speed at its highest level.
|
long |
getSpeed(int level)
Returns this AnimationInstance's speed at the specified level.
|
long |
getTimeFactor()
Returns this AnimationInstance's time factor.
|
AnimationInstance |
setGameState(GameState state)
Sets the GameState to which this AnimationInstance is assigned.
|
AnimationInstance |
setIndex(int index)
Sets this AnimationInstance's index at its highest level to the specified
value.
|
AnimationInstance |
setIndex(int level,
int index)
Sets this AnimationInstance's index at the specified level to the
specified value.
|
AnimationInstance |
setIndex(int level,
int index,
boolean resetLowerIndices)
Sets this AnimationInstance's index at the specified level to the
specified value.
|
AnimationInstance |
setSpeed(int level,
long speed)
Sets this AnimationInstance's speed at the specified level to the
specified value.
|
AnimationInstance |
setSpeed(long speed)
Sets this AnimationInstance's speed at its highest level to the specified
value.
|
AnimationInstance |
setTimeFactor(long timeFactor)
Sets this AnimationInstance's time factor to the specified value.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRenderableRegion
public static final AnimationInstance BLANK
public AnimationInstance(Animation animation)
animation
- The animation to make the AnimationInstance ofpublic final Sprite getCurrentSprite()
public final GameState getGameState()
public final AnimationInstance setGameState(GameState state)
state
- The GameState to which this AnimationInstance should be
assignedpublic final long getTimeFactor()
public final long getEffectiveTimeFactor()
public final AnimationInstance setTimeFactor(long timeFactor)
timeFactor
- The new time factorpublic final Animation getAnimation()
public final int getIndex(int level)
level
- The level of the index to be returnedjava.lang.IndexOutOfBoundsException
- if the specified level is not valid for
this AnimationInstancepublic final int getIndex()
public final AnimationInstance 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.java.lang.IndexOutOfBoundsException
- if this AnimationInstance does not have
the specified level, or the specified index is out of range at the
specified levelpublic final AnimationInstance setIndex(int level, int index)
level
- The level of the index to be setindex
- The value to which the index will be setjava.lang.IndexOutOfBoundsException
- if this AnimationInstance does not have
the specified level, or the specified index is out of range at the
specified levelpublic final AnimationInstance setIndex(int index)
index
- The value to which the index will be setjava.lang.IndexOutOfBoundsException
- if the specified index is out of rangepublic final long getSpeed(int level)
level
- The level of the speed to be returnedjava.lang.IndexOutOfBoundsException
- if the specified level is not valid for
this AnimationInstancepublic final long getSpeed()
public final AnimationInstance setSpeed(int level, long speed)
level
- The level of the speed to be setspeed
- The value to which the speed will be setjava.lang.IndexOutOfBoundsException
- if the specified level is not valid for
this AnimationInstancepublic final AnimationInstance setSpeed(long speed)
speed
- The value to which the speed will be setpublic final void draw(Graphics g, int x, int y)
Drawable
public final void draw(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 the image tox
- The x-coordinate on the Graphics context of the drawn image's
originy
- The y-coordinate on the Graphics context of the drawn image's
originxFlip
- If true, the drawn image is flipped along a vertical line
through its originyFlip
- If true, the drawn image is flipped along a horizontal line
through its originangle
- The angle in degrees by which to rotate the drawn image and
its xFlip and yFlip lines counterclockwise around its 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(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 the image tox
- The x-coordinate on the Graphics context of the drawn image's
originy
- The y-coordinate on the Graphics context of the drawn image's
originscale
- The factor by which to scale the drawn image around its
originxFlip
- If true, the drawn image is flipped along a vertical line
through its originyFlip
- If true, the drawn image is flipped along a horizontal line
through its 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(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 the region tox
- The x-coordinate on the Graphics context of the image's originy
- The y-coordinate on the Graphics context of the image's originleft
- The x-coordinate on the image, relative to its origin, of the
region's left edgeright
- The x-coordinate on the image, relative to its origin, of
the region's right edgetop
- The y-coordinate on the image, relative to its origin, of the
region's top edgebottom
- The y-coordinate on the image, relative to its origin, of
the region's bottom edgepublic final void draw(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 the region tox
- The x-coordinate on the Graphics context of the image's originy
- The y-coordinate on the Graphics context of the image's originleft
- The x-coordinate on the image, relative to its origin, of the
region's left edgeright
- The x-coordinate on the image, relative to its origin, of
the region's right edgetop
- The y-coordinate on the image, relative to its origin, of the
region's top edgebottom
- The y-coordinate on the image, relative to its origin, of
the 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(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 the region tox
- The x-coordinate on the Graphics context of the image's originy
- The y-coordinate on the Graphics context of the image's originleft
- The x-coordinate on the image, relative to its origin, of the
region's left edgeright
- The x-coordinate on the image, relative to its origin, of
the region's right edgetop
- The y-coordinate on the image, relative to its origin, of the
region's top edgebottom
- The y-coordinate on the image, relative to its origin, of
the region's bottom edgescale
- The factor by which to scale the drawn region around the
image's 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.