public abstract class Sprite extends Object
Surface
in a
DrawComponent
.
To be rendered a sprite must first be added to a draw component. Then to
update the rendered version after the initial attachment call the sprite's
redraw()
:
RectangleSprite rectangle = new RectangleSprite(100, 100); rectangle.setFill(RGB.RED); DrawComponent draw = new DrawComponent(100,100); draw.addSprite(rectangle);Sprites can also be redrawn by using the
DrawComponent.redrawSurface()
to tell the surface render all sprites
currently attached to it.Modifier and Type | Field and Description |
---|---|
protected PreciseRectangle |
clipRectangle |
protected boolean |
clipRectangleDirty |
protected DrawComponent |
component |
protected Color |
fill |
protected boolean |
fillDirty |
protected double |
fillOpacity |
protected boolean |
fillOpacityDirty |
protected boolean |
hidden |
protected boolean |
hiddenDirty |
protected Matrix |
matrix |
protected double |
opacity |
protected boolean |
opacityDirty |
protected Rotation |
rotation |
protected Scaling |
scaling |
protected Color |
stroke |
protected boolean |
strokeDirty |
protected double |
strokeOpacity |
protected boolean |
strokeOpacityDirty |
protected double |
strokeWidth |
protected boolean |
strokeWidthDirty |
protected Surface |
surface |
protected boolean |
transformDirty |
protected Translation |
translation |
protected int |
zIndex |
protected boolean |
zIndexDirty |
Constructor and Description |
---|
Sprite()
Creates a sprite and generates its id.
|
Sprite(Sprite sprite)
Creates a copy of the given sprite.
|
Modifier and Type | Method and Description |
---|---|
void |
clearDirtyFlags()
Clears all of the dirty flags on the sprite.
|
abstract Sprite |
copy()
Returns a copy of the sprite.
|
PreciseRectangle |
getBBox()
Returns the bounding box of the sprite.
|
PreciseRectangle |
getClipRectangle()
Returns the
PreciseRectangle that represents the clipping element. |
DrawComponent |
getComponent()
Returns the draw component that the sprite is attached.
|
Color |
getFill()
Returns the
Color of the sprite's fill. |
double |
getFillOpacity()
Returns the opacity of the sprite's fill.
|
double |
getOpacity()
Returns the opacity of the sprite.
|
abstract PathSprite |
getPathSprite()
Returns the
Sprite as a path. |
Rotation |
getRotation()
Returns the
Rotation of the sprite. |
Scaling |
getScaling()
Returns the
Scaling of the sprite. |
Color |
getStroke()
Returns the
Color of the stroke. |
double |
getStrokeOpacity()
Returns the opacity of the stroke.
|
double |
getStrokeWidth()
Returns the stroke width.
|
Surface |
getSurface()
Returns the sprite's surface.
|
Translation |
getTranslation()
Returns the
Translation of the sprite. |
int |
getZIndex()
Returns the z-index of the sprite.
|
boolean |
isClipRectangleDirty()
Returns true if the clip rectangle changed since the last render.
|
boolean |
isDirty()
Returns true if the sprite changed since the last render.
|
boolean |
isFillDirty()
Returns true if the fill changed since the last render.
|
boolean |
isFillOpacityDirty()
Returns true if the fill opacity changed since the last render.
|
boolean |
isHidden()
Returns true if the sprite is hidden.
|
boolean |
isHiddenDirty()
Returns true if the sprite's hidden value is dirty.
|
boolean |
isOpacityDirty()
Returns true if the opacity changed since the last render.
|
boolean |
isStrokeDirty()
Returns true if the stroke changed since the last render.
|
boolean |
isStrokeOpacityDirty()
Returns true if the stroke opacity changed since the last render.
|
boolean |
isStrokeWidthDirty()
Returns true if the stroke width changed since the last render.
|
boolean |
isTransformDirty()
Returns true if one of the sprite's transform values is dirty.
|
boolean |
isZIndexDirty()
Returns true if the sprite's z-index value is dirty.
|
void |
redraw()
Renders the sprite to its surface.
|
void |
remove()
Removes the sprite from its surface.
|
void |
setClipRectangle(PreciseRectangle clipRectangle)
Sets the
PreciseRectangle that represents the clipping element. |
void |
setComponent(DrawComponent component)
Sets the draw component that the sprite is attached.
|
void |
setCursor(String property)
Sets the cursor property of the sprite.
|
void |
setFill(Color fill)
Sets the
Color of the sprite's fill. |
void |
setFillOpacity(double fillOpacity)
Sets the opacity of the sprite's fill.
|
void |
setHidden(boolean hidden)
Sets true if the sprite is hidden.
|
void |
setOpacity(double opacity)
Sets the opacity of the sprite.
|
void |
setRotation(double degrees)
Sets the
Rotation of the sprite using the given angle. |
void |
setRotation(double x,
double y,
double degrees)
Sets the
Rotation of the sprite using the given coordinates and
angle. |
void |
setRotation(Rotation rotation)
Sets the
Rotation of the sprite. |
void |
setScaling(double scale)
Sets the
Scaling using the given scale value. |
void |
setScaling(double x,
double y,
double centerX,
double centerY)
Sets the
Scaling using the given x and y scale and the given
origin. |
void |
setScaling(Scaling scaling)
Sets the
Scaling of the sprite. |
void |
setStroke(Color stroke)
Sets the
Color of the stroke. |
void |
setStrokeOpacity(double strokeOpacity)
Sets the opacity of the stroke.
|
void |
setStrokeWidth(double strokeWidth)
Sets the stroke width.
|
void |
setSurface(Surface surface)
Sets the sprite's surface.
|
void |
setTranslation(double x,
double y)
Sets the
Translation of the sprite using the given x and y. |
void |
setTranslation(Translation translation)
Sets the
Translation of the sprite. |
void |
setZIndex(int zIndex)
Sets the z-index of the sprite.
|
protected void |
transformed()
Called any of the transforms are changed on the sprite.
|
Matrix |
transformMatrix()
Returns and caches the calculated transformation matrix.
|
void |
update(Sprite sprite)
Updates the attributes of the sprite using the given sprite.
|
protected double strokeWidth
protected boolean strokeWidthDirty
protected double fillOpacity
protected boolean fillOpacityDirty
protected double strokeOpacity
protected boolean strokeOpacityDirty
protected double opacity
protected boolean opacityDirty
protected Surface surface
protected DrawComponent component
protected Color stroke
protected boolean strokeDirty
protected Color fill
protected boolean fillDirty
protected Matrix matrix
protected Translation translation
protected Rotation rotation
protected Scaling scaling
protected PreciseRectangle clipRectangle
protected boolean clipRectangleDirty
protected int zIndex
protected boolean zIndexDirty
protected boolean transformDirty
protected boolean hiddenDirty
protected boolean hidden
public Sprite()
public Sprite(Sprite sprite)
sprite
- the sprite to be copiedpublic void clearDirtyFlags()
public abstract Sprite copy()
public PreciseRectangle getBBox()
public PreciseRectangle getClipRectangle()
PreciseRectangle
that represents the clipping element.public DrawComponent getComponent()
public Color getFill()
Color
of the sprite's fill.public double getFillOpacity()
public double getOpacity()
public abstract PathSprite getPathSprite()
Sprite
as a path.public Rotation getRotation()
Rotation
of the sprite.public Scaling getScaling()
Scaling
of the sprite.public Color getStroke()
Color
of the stroke.public double getStrokeOpacity()
public double getStrokeWidth()
public Surface getSurface()
public Translation getTranslation()
Translation
of the sprite.public int getZIndex()
public boolean isClipRectangleDirty()
public boolean isDirty()
public boolean isFillDirty()
public boolean isFillOpacityDirty()
public boolean isHidden()
public boolean isHiddenDirty()
public boolean isOpacityDirty()
public boolean isStrokeDirty()
public boolean isStrokeOpacityDirty()
public boolean isStrokeWidthDirty()
public boolean isTransformDirty()
public boolean isZIndexDirty()
public void redraw()
public void remove()
public void setClipRectangle(PreciseRectangle clipRectangle)
PreciseRectangle
that represents the clipping element.clipRectangle
- the rectangle that represents the clipping elementpublic void setComponent(DrawComponent component)
component
- the draw component that the sprite is attachedpublic void setCursor(String property)
property
- cursor propertypublic void setFill(Color fill)
Color
of the sprite's fill.fill
- the color of the sprite's fillpublic void setFillOpacity(double fillOpacity)
fillOpacity
- the opacity of the sprite's fillpublic void setHidden(boolean hidden)
hidden
- true if the sprite is hiddenpublic void setOpacity(double opacity)
opacity
- the opacity of the spritepublic void setRotation(double degrees)
Rotation
of the sprite using the given angle.degrees
- the angle of rotationpublic void setRotation(double x, double y, double degrees)
Rotation
of the sprite using the given coordinates and
angle.x
- the x-coordinate of rotationy
- the y-coordinate of rotationdegrees
- the angle of rotationpublic void setRotation(Rotation rotation)
Rotation
of the sprite.rotation
- the rotation of the spritepublic void setScaling(double scale)
Scaling
using the given scale value.scale
- the scale valuepublic void setScaling(double x, double y, double centerX, double centerY)
Scaling
using the given x and y scale and the given
origin.x
- the scale on the x axisy
- the scale on the y axiscenterX
- x-coordinate of the origincenterY
- y-coordinate of the originpublic void setScaling(Scaling scaling)
Scaling
of the sprite.scaling
- the scaling of the spritepublic void setStroke(Color stroke)
Color
of the stroke.stroke
- the color of the strokepublic void setStrokeOpacity(double strokeOpacity)
strokeOpacity
- the opacity of the strokepublic void setStrokeWidth(double strokeWidth)
strokeWidth
- the stroke widthpublic void setSurface(Surface surface)
surface
- the sprite's surfacepublic void setTranslation(double x, double y)
Translation
of the sprite using the given x and y.x
- the translation on the x-axisy
- the translation on the y-axispublic void setTranslation(Translation translation)
Translation
of the sprite.translation
- the translation of the spritepublic void setZIndex(int zIndex)
zIndex
- the z-index of the spritepublic Matrix transformMatrix()
public void update(Sprite sprite)
sprite
- the sprite attributes to useprotected void transformed()
Copyright © 2020. All rights reserved.