public class WeakSprite extends DefaultSprite
Sprite
caches tiles with WeakReference
in order to find a
balance between time and memoryConstructor and Description |
---|
WeakSprite(BufferedImage image,
int width,
int height)
Create a new sprite.
|
Modifier and Type | Method and Description |
---|---|
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.
|
draw, drawTile, getColumns, getRows, getSize, getTileCount, getTileHeight, getTileWidth
public WeakSprite(BufferedImage image, int width, int height)
BufferedImage
will be used as is. So consider passing
a copy of your original image. Calls to getTile(int, int)
will be buffered. So
changes maybe ignored or delayed. Calls to DefaultSprite.drawTile(Graphics2D, int, int, int, int)
won't be buffered.image
- The image that contains the sub-imageswidth
- Width of one sub-imageheight
- Height of one sub-imagepublic 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
getTile
in class DefaultSprite
x
- X-Coordinate of the tiley
- Y-Coordinate of the tileBufferedImage
containing the tilepublic Sprite getSubSprite(int x, int y, int width, int height)
Sprite
DerivedSprite
is linked with this
sprite.getSubSprite
in interface Sprite
getSubSprite
in class DefaultSprite
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.