public interface Sprite extends Image
Sprites work like images, but support modifications, such as scaling and filtering. They are recommended for dynamic uses, such as menus, entities or backgrounds elements (which are not statics).
For each modifications (scale, flip, rotate, filter...), the original surface is kept. So rotate(1)
followed by rotate(-1)
will give the same sprite as before.
There are two steps for the initialization:
load(boolean)
(this function will load the surface)
A non loaded sprite can be displayed (nothing will be displayed), but the sprite information are available (size). However, sprite manipulation will throw an exception as the surface is not available.
Example:// Load final Sprite sprite = Drawable.loadSprite(Media.get("sprite.png")); sprite.load(false); // Render sprite.render(g, 64, 280);
Modifier and Type | Method and Description |
---|---|
void |
filter(Filter filter)
Apply a filter to the sprite.
|
void |
flipHorizontal()
Flip the sprite horizontally (horizontal mirror).
|
void |
flipVertical()
Flip the sprite vertically (vertical mirror).
|
int |
getHeightOriginal()
Get the current sprite height (its current size, after scaling operation).
|
ImageBuffer |
getSurface()
Get the sprite surface.
|
int |
getWidthOriginal()
Get the current sprite width (its current size, after scaling operation).
|
void |
load(boolean alpha)
Load surface and prepare it to be displayed.
|
void |
render(Graphic g,
int x,
int y)
Render the sprite on graphic output at specified coordinates.
|
void |
rotate(int angle)
Rotate the sprite with the specified angle in degree.
|
void |
scale(int percent)
Method used for sprite scaling, in order to modify its size.
|
void |
setAlpha(int alpha)
Set alpha value.
|
void |
setTransparency(ColorRgba mask)
Set transparency color mask.
|
void |
stretch(int percentWidth,
int percentHeight)
Works as scale, but using different width and height factor.
|
getHeight, getWidth
void load(boolean alpha)
alpha
- Set true
to enable alpha, false
else.void scale(int percent)
100
, so
200
will scale it twice bigger, whereas 50
will scale half its size.percent
- The value for scaling in percent (> 0).void stretch(int percentWidth, int percentHeight)
percentWidth
- The percent value for scaling width (> 0).percentHeight
- The percent value for scaling height (> 0).void rotate(int angle)
angle
- The rotation angle in degree [0 - 360]
.void flipHorizontal()
void flipVertical()
void filter(Filter filter)
filter
- The filter to use.void setTransparency(ColorRgba mask)
mask
- The color mask.void setAlpha(int alpha)
alpha
- The alpha value [0 - 255]
.int getWidthOriginal()
int getHeightOriginal()
void render(Graphic g, int x, int y)
render
in interface Renderable
g
- The graphic output.x
- The horizontal location.y
- The vertical location.ImageBuffer getSurface()
getSurface
in interface Image