public class SpriteSheet extends java.lang.Object implements java.lang.Iterable<Sprite>, Loadable
A SpriteSheet is a rectangular grid of Sprites. Each Sprite has an x-coordinate in the grid that starts at 0 for the leftmost column and increases to the right, as well as a y-coordinate that starts at 0 for the topmost row and increases below. Like other Loadables, SpriteSheets can be manually loaded and unloaded into and out of memory. Loading may take a moment, but a SpriteSheet's Sprites cannot be loaded and drawn if the SpriteSheet itself is not loaded. Loading a SpriteSheet will also load all of its Sprites, and loading a Sprite that is part of a SpriteSheet will also load that SpriteSheet.
A SpriteSheet has a fixed set of Filters, specified upon its creation, that can have an effect on its Sprites when applied to them with their draw() methods. The SpriteSheet makes this possible by making a copy of its image data with each Filter applied upon being loaded. Thus, the amount of memory that a loaded SpriteSheet occupies is proportional to its number of applicable Filters plus 1.
Constructor and Description |
---|
SpriteSheet(SpriteSheet spriteSheet,
Filter filter,
boolean load)
Constructs a SpriteSheet from an existing SpriteSheet with a Filter
applied to it.
|
SpriteSheet(java.lang.String path,
int width,
int height,
int spriteWidth,
int spriteHeight,
int spacing,
int margin,
int originX,
int originY,
boolean load,
Filter... filters)
Constructs a SpriteSheet from an image file.
|
SpriteSheet(java.lang.String path,
int width,
int height,
int spriteWidth,
int spriteHeight,
int spacing,
int margin,
int originX,
int originY,
Color transColor,
boolean load,
Filter... filters)
Constructs a SpriteSheet from an image file.
|
SpriteSheet(java.lang.String path,
int width,
int height,
int spriteWidth,
int spriteHeight,
int spacing,
int margin,
int originX,
int originY,
int transR,
int transG,
int transB,
boolean load,
Filter... filters)
Constructs a SpriteSheet from an image file.
|
Modifier and Type | Method and Description |
---|---|
java.util.Set<Filter> |
getFilters()
Returns an unmodifiable Set view of the Filters that will have an effect
on this SpriteSheet's Sprites when applied to them with draw().
|
int |
getHeight()
Returns the height in Sprites of this SpriteSheet.
|
int |
getMargin()
Returns the horizontal and vertical spacing in pixels between this
SpriteSheet's grid of Sprites and the edges of its image.
|
int |
getOriginX()
Returns the x-coordinate in pixels on each of this SpriteSheet's Sprites
of that Sprite's origin.
|
int |
getOriginY()
Returns the y-coordinate in pixels on each of this SpriteSheet's Sprites
of that Sprite's origin.
|
int |
getSpacing()
Returns the horizontal and vertical spacing in pixels between Sprites in
this SpriteSheet.
|
Sprite |
getSprite(int x,
int y)
Returns this SpriteSheet's Sprite at the specified coordinates.
|
int |
getSpriteHeight()
Returns the height in pixels of each of this SpriteSheet's sprites.
|
int |
getSpriteWidth()
Returns the width in pixels of each of this SpriteSheet's sprites.
|
int |
getWidth()
Returns the width in Sprites of this SpriteSheet.
|
boolean |
isLoaded()
Returns whether this Loadable is loaded.
|
java.util.Iterator<Sprite> |
iterator()
Returns an Iterator over this SpriteSheet's Sprites.
|
boolean |
load()
Loads this SpriteSheet, along with all of its Sprites, if it is not
already loaded.
|
boolean |
unload()
Unloads this SpriteSheet, along with all of its Sprites, if it is
currently loaded.
|
public SpriteSheet(java.lang.String path, int width, int height, int spriteWidth, int spriteHeight, int spacing, int margin, int originX, int originY, boolean load, Filter... filters)
path
- The relative path to the image filewidth
- The width in Sprites of this SpriteSheetheight
- The height in Sprites of this SpriteSheetspriteWidth
- The width in pixels of each SpritespriteHeight
- The height in pixels of each Spritespacing
- The horizontal and vertical spacing in pixels between
Spritesmargin
- The horizontal and vertical spacing in pixels between the
grid of Sprites and the edges of the imageoriginX
- The x-coordinate in pixels on each Sprite of that Sprite's
originoriginY
- The y-coordinate in pixels on each Sprite of that Sprite's
originload
- Whether this SpriteSheet should load upon creationfilters
- The Filters that will have an effect on this SpriteSheet's
Sprites when applied to them with draw()public SpriteSheet(java.lang.String path, int width, int height, int spriteWidth, int spriteHeight, int spacing, int margin, int originX, int originY, Color transColor, boolean load, Filter... filters)
path
- The relative path to the image filewidth
- The width in Sprites of this SpriteSheetheight
- The height in Sprites of this SpriteSheetspriteWidth
- The width in pixels of each SpritespriteHeight
- The height in pixels of each Spritespacing
- The horizontal and vertical spacing in pixels between
Spritesmargin
- The horizontal and vertical spacing in pixels between the
grid of Sprites and the edges of the imageoriginX
- The x-coordinate in pixels on each Sprite of that Sprite's
originoriginY
- The y-coordinate in pixels on each Sprite of that Sprite's
origintransColor
- The transparent color of this SpriteSheet's Sprites, or
null if there should be noneload
- Whether this SpriteSheet should load upon creationfilters
- The Filters that will have an effect on this SpriteSheet's
Sprites when applied to them with draw()public SpriteSheet(java.lang.String path, int width, int height, int spriteWidth, int spriteHeight, int spacing, int margin, int originX, int originY, int transR, int transG, int transB, boolean load, Filter... filters)
path
- The relative path to the image filewidth
- The width in Sprites of this SpriteSheetheight
- The height in Sprites of this SpriteSheetspriteWidth
- The width in pixels of each SpritespriteHeight
- The height in pixels of each Spritespacing
- The horizontal and vertical spacing in pixels between
Spritesmargin
- The horizontal and vertical spacing in pixels between the
grid of Sprites and the edges of the imageoriginX
- The x-coordinate in pixels on each Sprite of that Sprite's
originoriginY
- The y-coordinate in pixels on each Sprite of that Sprite's
origintransR
- The red value (0-255) of this SpriteSheet's Sprites'
transparent colortransG
- The green value (0-255) of this SpriteSheet's Sprites'
transparent colortransB
- The blue value (0-255) of this SpriteSheet's Sprites'
transparent colorload
- Whether this SpriteSheet should load upon creationfilters
- The Filters that will have an effect on this SpriteSheet's
Sprites when applied to them with draw()public SpriteSheet(SpriteSheet spriteSheet, Filter filter, boolean load)
spriteSheet
- The SpriteSheet to create this SpriteSheet fromfilter
- The Filter to apply to the existing SpriteSheetload
- Whether this SpriteSheet should load upon creationpublic final java.util.Iterator<Sprite> iterator()
iterator
in interface java.lang.Iterable<Sprite>
public final boolean isLoaded()
Loadable
public final boolean load()
public final boolean unload()
public final java.util.Set<Filter> getFilters()
public final int getWidth()
public final int getHeight()
public Sprite getSprite(int x, int y)
x
- The x-coordinate in Sprites of the Spritey
- The y-coordinate in Sprites of the Spritejava.lang.IndexOutOfBoundsException
- if the location is out of this
SpriteSheet's boundspublic final int getSpriteWidth()
public final int getSpriteHeight()
public final int getSpacing()
public final int getMargin()
public final int getOriginX()
public final int getOriginY()