public class Sprite extends java.lang.Object implements Animatable, Drawable
A Sprite is a static image that can be drawn to a Graphics context. Like SpriteSheets, Sounds, and Music tracks, Sprites can be manually loaded and unloaded into and out of memory. Loading may take a moment, but while a Sprite is not loaded, it cannot be drawn. A Sprite may also be treated as an Animatable with exactly one frame, namely itself, that has a duration of 0.
Filter
,
SpriteSheet
,
Animation
Modifier and Type | Field and Description |
---|---|
static Sprite |
BLANK
A blank Sprite with no appearance.
|
Constructor and Description |
---|
Sprite(Image image)
Constructs a Sprite from a Celick Image.
|
Sprite(Sprite sprite,
Filter filter,
boolean load)
Constructs a Sprite from an existing Sprite with a Filter applied to it.
|
Sprite(java.lang.String path,
int originX,
int originY,
Color transColor,
java.util.Set<Filter> filters,
boolean load)
Constructs a Sprite from an image file.
|
Sprite(java.lang.String path,
int originX,
int originY,
int transR,
int transG,
int transB,
java.util.Set<Filter> filters,
boolean load)
Constructs a Sprite from an image file.
|
Sprite(java.lang.String path,
int originX,
int originY,
java.util.Set<Filter> filters,
boolean load)
Constructs a Sprite from an image file.
|
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.
|
boolean |
framesAreCompatible(int index1,
int index2)
Returns whether the two frames at the specified indices are compatible
for AnimationInstances' transitioning purposes.
|
java.util.Set<Filter> |
getFilters()
Returns an unmodifiable Set view of the Filters that will have an effect
on this Sprite when applied to it with draw().
|
Animatable |
getFrame(int index)
Returns this Animatable's frame at the specified index.
|
long |
getFrameDuration(int index)
Returns the duration of the frame at the specified index.
|
int |
getHeight()
Returns this Sprite's height in pixels.
|
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.
|
int |
getOriginX()
Returns the x-coordinate in pixels of this Sprite's origin.
|
int |
getOriginY()
Returns the y-coordinate in pixels of this Sprite's origin.
|
SpriteSheet |
getSpriteSheet()
Returns the SpriteSheet that this Sprite is part of, or null if it is not
part of one.
|
int |
getWidth()
Returns this Sprite's width in pixels.
|
boolean |
isLoaded()
Returns whether this Sprite is loaded.
|
boolean |
load()
Loads this Sprite if it is not already loaded.
|
boolean |
unload()
Unloads this Sprite if it is currently loaded.
|
public static final Sprite BLANK
public Sprite(java.lang.String path, int originX, int originY, java.util.Set<Filter> filters, boolean load)
path
- The relative path to the image fileoriginX
- The x-coordinate in pixels of the origin on the imageoriginY
- The y-coordinate in pixels of the origin on the imagefilters
- The Set of Filters that should have an effect on this
Sprite when applied to it with draw(), or null if no Filters should have
an effectload
- Whether this Sprite should load upon creationpublic Sprite(java.lang.String path, int originX, int originY, Color transColor, java.util.Set<Filter> filters, boolean load)
path
- The relative path to the image fileoriginX
- The x-coordinate in pixels of the origin on the imageoriginY
- The y-coordinate in pixels of the origin on the imagetransColor
- This Sprite's transparent color, or null if there
should be nonefilters
- The Set of Filters that should have an effect on this
Sprite when applied to it with draw(), or null if no Filters should have
an effectload
- Whether this Sprite should load upon creationpublic Sprite(java.lang.String path, int originX, int originY, int transR, int transG, int transB, java.util.Set<Filter> filters, boolean load)
path
- The relative path to the image fileoriginX
- The x-coordinate in pixels of the origin on the imageoriginY
- The y-coordinate in pixels of the origin on the imagetransR
- The red value (0-255) of this Sprite's transparent colortransG
- The green value (0-255) of this Sprite's transparent colortransB
- The blue value (0-255) of this Sprite's transparent colorfilters
- The Set of Filters that should have an effect on this
Sprite when applied to it with draw(), or null if no Filters should have
an effectload
- Whether this Sprite should load upon creationpublic Sprite(Image image)
image
- The Image to create this Sprite frompublic Sprite(Sprite sprite, Filter filter, boolean load)
sprite
- The Sprite to create this Sprite fromfilter
- The Filter to apply to the existing Spriteload
- Whether this Sprite should load upon creationpublic final boolean isLoaded()
public final boolean load()
public final boolean unload()
public 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 SpriteSheet getSpriteSheet()
public final java.util.Set<Filter> getFilters()
public final int getOriginX()
public final int getOriginY()
public final int getWidth()
public final int getHeight()
public 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.