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.
Modifier and Type | Field and Description |
---|---|
static Sprite |
BLANK
A blank Sprite with no appearance.
|
Constructor and Description |
---|
Sprite(Sprite sprite,
Filter filter,
boolean load)
Creates a new Sprite from an existing Sprite with a Filter applied to it.
|
Sprite(java.lang.String path,
int originX,
int originY,
org.newdawn.slick.Color transColor,
java.util.Set<Filter> filters,
boolean load)
Creates a new 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)
Creates a new Sprite from an image file.
|
Sprite(java.lang.String path,
int originX,
int originY,
java.util.Set<Filter> filters,
boolean load)
Creates a new Sprite from an image file.
|
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.
|
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 the Set of 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) throws org.newdawn.slick.SlickException
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 will have an effect on this Sprite
when applied to it with draw()load
- Whether this Sprite should load upon creationorg.newdawn.slick.SlickException
- If the Sprite could not be properly loaded from
the specified pathpublic Sprite(java.lang.String path, int originX, int originY, org.newdawn.slick.Color transColor, java.util.Set<Filter> filters, boolean load) throws org.newdawn.slick.SlickException
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 will have an effect on this Sprite
when applied to it with draw()load
- Whether this Sprite should load upon creationorg.newdawn.slick.SlickException
- If the Sprite could not be properly loaded from
the specified pathpublic Sprite(java.lang.String path, int originX, int originY, int transR, int transG, int transB, java.util.Set<Filter> filters, boolean load) throws org.newdawn.slick.SlickException
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 R value (0-255) of this Sprite's transparent colortransG
- The G value (0-255) of this Sprite's transparent colortransB
- The B value (0-255) of this Sprite's transparent colorfilters
- The Set of Filters that will have an effect on this Sprite
when applied to it with draw()load
- Whether this Sprite should load upon creationorg.newdawn.slick.SlickException
- If the Sprite could not be properly loaded from
the specified pathpublic Sprite(Sprite sprite, Filter filter, boolean load) throws org.newdawn.slick.SlickException
sprite
- The Sprite to create this Sprite fromfilter
- The Filter to apply to the existing Spriteload
- Whether this Sprite should load upon creationorg.newdawn.slick.SlickException
- If the Sprite could not be properly loadedpublic final boolean isLoaded()
public final boolean load() throws org.newdawn.slick.SlickException
org.newdawn.slick.SlickException
- If the Sprite could not be properly loadedpublic 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 getWidth()
public final int getHeight()
public final int getOriginX()
public final int getOriginY()
public 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.