|
PulpCore | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object pulpcore.sprite.Sprite
public abstract class Sprite
The superclass of all sprites. Contains location, dimension, alpha,
angle, visibility, and anchor information.
The Sprite does no drawing - subclasses implement the
drawSprite(CoreGraphics)
method to draw.
Field Summary | |
---|---|
Int |
alpha
The alpha of this Sprite, in range from 0 to 255. |
Fixed |
anchorX
The x anchor point of this Sprite, in range from 0.0 to 1.0. |
Fixed |
anchorY
The y anchor point of this Sprite, in range from 0.0 to 1.0. |
Fixed |
angle
The angle of this Sprite, typically in range from 0 to 2*PI, although the angle can have any value. |
static int |
CENTER
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
static int |
DEFAULT
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
static int |
EAST
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
Bool |
enabled
The flag indicating whether this Sprite is enabled. |
Fixed |
height
The height of this Sprite. |
static int |
NORTH
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
static int |
NORTH_EAST
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
static int |
NORTH_WEST
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
Bool |
pixelSnapping
Sets whether pixel snapping enabled for rendering this Sprite. |
static int |
SOUTH
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
static int |
SOUTH_EAST
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
static int |
SOUTH_WEST
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
Bool |
visible
The flag indicating whether or not this Sprite is visible. |
static int |
WEST
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
Fixed |
width
The width of this Sprite. |
Fixed |
x
The x location of this Sprite. |
Fixed |
y
The y location of this Sprite. |
Constructor Summary | |
---|---|
Sprite(double x,
double y,
double width,
double height)
|
|
Sprite(int x,
int y,
int width,
int height)
|
Method Summary | |
---|---|
void |
bindLocationTo(Sprite sprite)
Binds this sprite's location to that of the specified sprite. |
void |
bindSizeTo(Sprite sprite)
Binds this sprite's size to that of the specified sprite. |
void |
clearCursor()
Clears the cursor for this Sprite, so that it's parent cursor is used. |
void |
clearDirtyRect()
For dirty rectangles - most apps will not need ot call this method directly. |
boolean |
contains(int viewX,
int viewY)
Checks if the specified location is within the bounds of this Sprite. |
void |
draw(CoreGraphics g)
Draws the Sprite. |
protected abstract void |
drawSprite(CoreGraphics g)
Draws the sprite. |
BlendMode |
getBlendMode()
|
int |
getCursor()
Gets the cursor for this Sprite. |
Rect |
getDirtyRect()
For dirty rectangles - most apps will not need ot call this method directly. |
Filter |
getFilter()
Gets the image filter for this Sprite, or null if there is no filter. |
double |
getLocalX(double viewX,
double viewY)
Gets the integer x-coordinate in Local Space of the specified location in View Space. |
double |
getLocalY(double viewX,
double viewY)
Gets the integer y-coordinate in Local Space of the specified location in View Space. |
protected int |
getNaturalHeight()
Gets the fixed-point value of the Sprite's natural height. |
protected int |
getNaturalWidth()
Gets the fixed-point value of the Sprite's natural width. |
Group |
getParent()
Gets this Sprite's parent Group, or null if this Sprite does not have a parent. |
boolean |
getPixelLevelChecks()
Returns true if this sprite should use pixel-level checks for intersections and picking. |
Group |
getRoot()
Gets this Sprite's oldest ancestor Group, or null if this Sprite does not have a parent. |
Scene2D |
getScene2D()
Gets the Scene2D this Sprite belongs to, or null if
this Sprite is not in a Scene2D. |
Object |
getTag()
Gets this Sprite's tag. |
double |
getViewX()
Gets the x-coordinate of this sprite in View Space. |
double |
getViewX(double localX,
double localY)
Gets the x-coordinate in View Space of the specified location in Local Space. |
double |
getViewY()
Gets the y-coordinate of this sprite in View Space. |
double |
getViewY(double localX,
double localY)
Gets the y-coordinate in View Space of the specified location in Local Space. |
boolean |
intersects(Sprite sprite)
Checks if the specified sprite intersects this sprite. |
boolean |
isDirty()
Returns true if the Sprite's properties have changed since the last call to draw() |
boolean |
isEnabled()
Returns true if this Sprite's enabled property is set to true and its parent, if any, is enabled. |
boolean |
isEnabledAndVisible()
Returns true if this Sprite's enabled property is set to true, its visible property set to true, its alpha property is greater than zero, and its parent, if any, is enabled and visible. |
boolean |
isMouseDoubleClicked()
Checks if this Sprite (and its parents) are enabled, the primary mouse button was double-clicked since the last update, and the double-click occurred within this Sprite's bounds. |
boolean |
isMouseDown()
Checks if this Sprite (and its parents) are enabled, the mouse is currently within the bounds of this Sprite, and the primary mouse button is pressed down. |
boolean |
isMouseHover()
Checks if this Sprite (and its parents) are enabled, the mouse is within the bounds of this Sprite, and the primary mouse button is not pressed down. |
boolean |
isMouseOver()
Checks if this Sprite (and its parents) are enabled, and the mouse is currently within the bounds of this Sprite. |
boolean |
isMousePressed()
Checks if this Sprite (and its parents) are enabled, the primary mouse button was pressed since the last update, and the press occurred within this Sprite's bounds. |
boolean |
isMouseReleased()
Checks if this Sprite (and its parents) are enabled, the primary mouse button was released since the last update, and the release occurred within this Sprite's bounds. |
boolean |
isMouseTripleClicked()
Checks if this Sprite (and its parents) are enabled, the primary mouse button was triple-clicked since the last update, and the triple-click occurred within this Sprite's bounds. |
boolean |
isMouseWheelRotated()
Checks if this Sprite (and its parents) are enabled and the mouse wheel was rotated over this Sprite. |
boolean |
isOpaque()
Returns true if this Sprite is opaque. |
boolean |
isPick(int viewX,
int viewY)
Checks if the specified location is within the bounds of this Sprite and this Sprite is the top-most Sprite at that location. |
boolean |
isPickEnabledAndVisible(int viewX,
int viewY)
Checks if the specified location is within the bounds of this Sprite and this Sprite is the top-most visible and enabled Sprite at that location. |
protected boolean |
isTransparent(int localX,
int localY)
Checks if the pixel at the specified integer location is transparent. |
void |
move(double startX,
double startY,
double endX,
double endY,
int duration)
|
void |
move(double startX,
double startY,
double endX,
double endY,
int duration,
Easing easing)
|
void |
move(double startX,
double startY,
double endX,
double endY,
int duration,
Easing easing,
int startDelay)
|
void |
move(int startX,
int startY,
int endX,
int endY,
int duration)
|
void |
move(int startX,
int startY,
int endX,
int endY,
int duration,
Easing easing)
|
void |
move(int startX,
int startY,
int endX,
int endY,
int duration,
Easing easing,
int startDelay)
|
void |
moveTo(double x,
double y,
int duration)
|
void |
moveTo(double x,
double y,
int duration,
Easing easing)
|
void |
moveTo(double x,
double y,
int duration,
Easing easing,
int startDelay)
|
void |
moveTo(int x,
int y,
int duration)
|
void |
moveTo(int x,
int y,
int duration,
Easing easing)
|
void |
moveTo(int x,
int y,
int duration,
Easing easing,
int startDelay)
|
void |
propertyChange(Property property)
On a property change this Sprite is marked as dirty. |
void |
removeFromParent()
Removes this Sprite from its parent Group. |
void |
scale(double width1,
double height1,
double width2,
double height2,
int duration)
|
void |
scale(double width1,
double height1,
double width2,
double height2,
int duration,
Easing easing)
|
void |
scale(double width1,
double height1,
double width2,
double height2,
int duration,
Easing easing,
int startDelay)
|
void |
scale(int width1,
int height1,
int width2,
int height2,
int duration)
|
void |
scale(int width1,
int height1,
int width2,
int height2,
int duration,
Easing easing)
|
void |
scale(int width1,
int height1,
int width2,
int height2,
int duration,
Easing easing,
int startDelay)
|
void |
scaleTo(double width,
double height,
int duration)
|
void |
scaleTo(double width,
double height,
int duration,
Easing easing)
|
void |
scaleTo(double width,
double height,
int duration,
Easing easing,
int startDelay)
|
void |
scaleTo(int width,
int height,
int duration)
|
void |
scaleTo(int width,
int height,
int duration,
Easing easing)
|
void |
scaleTo(int width,
int height,
int duration,
Easing easing,
int startDelay)
|
void |
setAnchor(double anchorX,
double anchorY)
Sets the anchor of this Sprite. |
void |
setAnchor(int anchor)
Deprecated. Compass directions are being phased out - Use setAnchor(double, double) instead. |
void |
setBlendMode(BlendMode blendMode)
Sets the blend mode used to draw this Sprite. |
void |
setCursor(int cursor)
Sets the cursor for this Sprite. |
void |
setDirty(boolean dirty)
Marks this Sprite as dirty, which will force it to redraw on the next frame. |
void |
setFilter(Filter filter)
Sets the image filter for this Sprite. |
void |
setLocation(double x,
double y)
Sets the location of this Sprite. |
void |
setLocation(int x,
int y)
Sets the location of this Sprite. |
void |
setSize(double width,
double height)
Sets the size of this Sprite. |
void |
setSize(int width,
int height)
Sets the size of this Sprite. |
void |
setTag(Object tag)
Sets this Sprite's tag. |
void |
translate(double x,
double y)
Translates the location of this Sprite. |
void |
translate(int x,
int y)
Translates the location of this Sprite. |
void |
update(int elapsedTime)
Updates all of this Sprite's properties. |
boolean |
updateDirtyRect()
For dirty rectangles - most apps will not need ot call this method directly. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT
setAnchor(double, double)
instead.
public static final int NORTH
setAnchor(double, double)
instead.
public static final int SOUTH
setAnchor(double, double)
instead.
public static final int WEST
setAnchor(double, double)
instead.
public static final int EAST
setAnchor(double, double)
instead.
public static final int NORTH_WEST
setAnchor(double, double)
instead.
public static final int NORTH_EAST
setAnchor(double, double)
instead.
public static final int SOUTH_WEST
setAnchor(double, double)
instead.
public static final int SOUTH_EAST
setAnchor(double, double)
instead.
public static final int CENTER
setAnchor(double, double)
instead.
public final Bool enabled
public final Fixed x
public final Fixed y
public final Fixed width
public final Fixed height
public final Fixed anchorX
public final Fixed anchorY
public final Fixed angle
public final Int alpha
public final Bool visible
public final Bool pixelSnapping
Enabling pixel snapping may allow some type of images (e.g. pixel art) to look better.
This value is false by default.
Constructor Detail |
---|
public Sprite(int x, int y, int width, int height)
public Sprite(double x, double y, double width, double height)
Method Detail |
---|
public Object getTag()
setTag(Object)
,
Group.findWithTag(Object)
public void setTag(Object tag)
null
.
getTag()
,
Group.findWithTag(Object)
public boolean isOpaque()
Returns false by default.
public final Group getParent()
public void removeFromParent()
public final Group getRoot()
public Scene2D getScene2D()
Scene2D
this Sprite belongs to, or null
if
this Sprite is not in a Scene2D.
public final boolean isEnabled()
public final boolean isEnabledAndVisible()
public final Rect getDirtyRect()
public final boolean updateDirtyRect()
public final void clearDirtyRect()
public final void setDirty(boolean dirty)
public final boolean isDirty()
protected int getNaturalWidth()
ImageSprite
, the natural width is the
width of the image.
protected int getNaturalHeight()
ImageSprite
, the natural height is the
height of the image.
public void setAnchor(int anchor)
setAnchor(double, double)
instead.
DEFAULT
,
NORTH
, SOUTH
, WEST
, EAST
,
NORTH_WEST
, SOUTH_WEST
, NORTH_EAST
, SOUTH_EAST
, or
CENTER
.
NW N NE +----+----+ | | W + * + E | | +----+----+ SW S SEThe
DEFAULT
anchor is equivalent to NORTH_WEST
for most Sprites (except
for ImageSprites, which use the CoreImage's hotspot as the anchor).
public final void setAnchor(double anchorX, double anchorY)
(0.0,0.0) (0.5,0.0) (1.0,0.0) +----------+----------+ | | | | | | | (0.5,0.5) | (0.0,0.5) + * + (1.0,0.5) | | | | | | | | +----------+----------+ (0.0,0.0) (0.5,1.0) (1.0,1.0)For example, to center the Sprite at it's (x,y) location, use
sprite.setAnchor(0.5, 0.5);
anchorX
,
anchorY
public final void setCursor(int cursor)
Scene2D
.
Input
,
getCursor()
,
clearCursor()
public final void clearCursor()
Input
,
getCursor()
,
setCursor(int)
public final int getCursor()
Input
,
setCursor(int)
,
clearCursor()
public final void setBlendMode(BlendMode blendMode)
BlendMode
public final BlendMode getBlendMode()
public final void setFilter(Filter filter)
null
.
If the specified filter is already attached to a Sprite, a clone of it is created.
getFilter()
public final Filter getFilter()
setFilter(pulpcore.image.filter.Filter)
public void update(int elapsedTime)
public void propertyChange(Property property)
propertyChange
in interface PropertyListener
property
- the property whose value has changed.public final void draw(CoreGraphics g)
drawSprite(pulpcore.image.CoreGraphics)
.
protected abstract void drawSprite(CoreGraphics g)
This method may be called multiple times for each dirty rectangle. The clip of the graphics context will be set to the current dirty rectangle.
When the contents of this sprite change (in another words, the graphic output of this method
will be different from the last time it is called), subclasses should call
setDirty(true)
.
Implementors should not save a reference to the graphics context as it can change between calls to this method.
public final double getLocalX(double viewX, double viewY)
public final double getLocalY(double viewX, double viewY)
public final double getViewX()
public final double getViewY()
public final double getViewX(double localX, double localY)
public final double getViewY(double localX, double localY)
public final boolean contains(int viewX, int viewY)
viewX
- x-coordinate in view spaceviewY
- y-coordinate in view space
public boolean getPixelLevelChecks()
This method returns false. Subclasses of Sprite should override this method if they
have pixel-level checks in their implementation of isTransparent(int, int)
.
protected boolean isTransparent(int localX, int localY)
The default implementation always returns false. Subclasses of this class may need to override this method to return accurate results.
This method is called from contains(int,int)
.
localX
- integer x-coordinate in local spacelocalY
- integer y-coordinate in local spacepublic final boolean isPick(int viewX, int viewY)
viewX
- x-coordinate in view spaceviewY
- y-coordinate in view spacepublic final boolean isPickEnabledAndVisible(int viewX, int viewY)
viewX
- x-coordinate in view spaceviewY
- y-coordinate in view spacepublic boolean intersects(Sprite sprite)
The two sprites do no have to be in the same Group.
sprite
- the sprite to test against.
public boolean isMouseOver()
For a typical button UI button behavior, use Button
.
public boolean isMouseHover()
For a typical button UI button behavior, use Button
.
public boolean isMouseDown()
For a typical button UI button behavior, use Button
.
public boolean isMousePressed()
For a typical button UI button behavior, use Button
.
public boolean isMouseReleased()
For a typical button UI button behavior, use Button
.
public boolean isMouseDoubleClicked()
For a typical button UI button behavior, use Button
.
public boolean isMouseTripleClicked()
For a typical button UI button behavior, use Button
.
public boolean isMouseWheelRotated()
public void setLocation(int x, int y)
public void setLocation(double x, double y)
public void translate(int x, int y)
public void translate(double x, double y)
public void setSize(int width, int height)
public void setSize(double width, double height)
public void bindLocationTo(Sprite sprite)
public void bindSizeTo(Sprite sprite)
public void move(int startX, int startY, int endX, int endY, int duration)
public void move(int startX, int startY, int endX, int endY, int duration, Easing easing)
public void move(int startX, int startY, int endX, int endY, int duration, Easing easing, int startDelay)
public void moveTo(int x, int y, int duration)
public void moveTo(int x, int y, int duration, Easing easing)
public void moveTo(int x, int y, int duration, Easing easing, int startDelay)
public void move(double startX, double startY, double endX, double endY, int duration)
public void move(double startX, double startY, double endX, double endY, int duration, Easing easing)
public void move(double startX, double startY, double endX, double endY, int duration, Easing easing, int startDelay)
public void moveTo(double x, double y, int duration)
public void moveTo(double x, double y, int duration, Easing easing)
public void moveTo(double x, double y, int duration, Easing easing, int startDelay)
public void scale(int width1, int height1, int width2, int height2, int duration)
public void scale(int width1, int height1, int width2, int height2, int duration, Easing easing)
public void scale(int width1, int height1, int width2, int height2, int duration, Easing easing, int startDelay)
public void scaleTo(int width, int height, int duration)
public void scaleTo(int width, int height, int duration, Easing easing)
public void scaleTo(int width, int height, int duration, Easing easing, int startDelay)
public void scale(double width1, double height1, double width2, double height2, int duration)
public void scale(double width1, double height1, double width2, double height2, int duration, Easing easing)
public void scale(double width1, double height1, double width2, double height2, int duration, Easing easing, int startDelay)
public void scaleTo(double width, double height, int duration)
public void scaleTo(double width, double height, int duration, Easing easing)
public void scaleTo(double width, double height, int duration, Easing easing, int startDelay)
|
PulpCore | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |