Modifier | Constructor and Description |
---|---|
protected |
DefaultSprite()
When using this constructor you'll have to override all methods.
|
|
DefaultSprite(BufferedImage image,
int width,
int height)
Create a new sprite.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(Graphics2D g,
int width,
int height)
Draws the image on a given
Graphics2D object |
void |
drawTile(Graphics2D g,
int x,
int y,
int width,
int height)
Draws a tile of this sprite.
|
int |
getColumns()
Get the number of columns.
|
int |
getRows()
Get the number of rows.
|
Size |
getSize()
Get the original size of the image
|
Sprite |
getSubSprite(int x,
int y,
int width,
int height)
Get sub-sprite with given dimension.
|
BufferedImage |
getTile(int x,
int y)
Get a tile of this sprite.
|
int |
getTileCount()
Get the number of tiles in this sprite.
|
int |
getTileHeight()
Get the height of one tile
|
int |
getTileWidth()
Get the width of one tile
|
public DefaultSprite(BufferedImage image, int width, int height)
BufferedImage
will be used as is. So consider passing
a copy of your original image.image
- The image that contains the sub-imageswidth
- Width of one sub-imageheight
- Height of one sub-imageprotected DefaultSprite()
public void drawTile(Graphics2D g, int x, int y, int width, int height)
Sprite
Bounds(0, 0,
width, height)
. Consider creating a clipped Graphics2D
object.drawTile
in interface Sprite
g
- Graphics2D
object to draw onx
- X-Coordinate of the tiley
- Y-Coordinate of the tilewidth
- The width of the Graphics object to draw onheight
- The height of the Graphics object to draw onpublic void draw(Graphics2D g, int width, int height)
Image
Graphics2D
objectpublic BufferedImage getTile(int x, int y)
Sprite
Sprite.drawTile(Graphics2D, int, int, int, int)
for faster action and less memory
usage.getTile
in interface Sprite
x
- X-Coordinate of the tiley
- Y-Coordinate of the tileBufferedImage
containing the tilepublic Size getSize()
Image
public int getTileCount()
Sprite
getTileCount
in interface Sprite
public int getRows()
Sprite
public int getColumns()
Sprite
getColumns
in interface Sprite
public int getTileWidth()
Sprite
getTileWidth
in interface Sprite
public int getTileHeight()
Sprite
getTileHeight
in interface Sprite
public Sprite getSubSprite(int x, int y, int width, int height)
Sprite
DerivedSprite
is linked with this
sprite.getSubSprite
in interface Sprite
x
- X-Coordinate of first tiley
- Y-Coordinate of first tilewidth
- Width of the sub-spriteheight
- Height of the sub-spriteDerivedSprite
Copyright © 2017. All rights reserved.