public abstract class Sprite extends AbstractMedia implements DirectionCodes, Pathable
HUD_LAYERCARDINAL_DIRECTIONS, CCW, CW, DIRECTION_COUNT, DOWN, EAST, EASTNORTHEAST, EASTSOUTHEAST, FINE_DIRECTION_COUNT, HORIZONTAL, LEFT, NONE, NORTH, NORTHEAST, NORTHNORTHEAST, NORTHNORTHWEST, NORTHWEST, RIGHT, SOUTH, SOUTHEAST, SOUTHSOUTHEAST, SOUTHSOUTHWEST, SOUTHWEST, UP, VERTICAL, WEST, WESTNORTHWEST, WESTSOUTHWEST| Constructor and Description |
|---|
Sprite()
Constructs a sprite with an initially invalid location.
|
Sprite(int width,
int height)
Constructs a sprite with the supplied dimensions.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSpriteObserver(Object obs)
Add a sprite observer to observe this sprite's events.
|
void |
cancelMove()
Cancels any path that the sprite may currently be moving along.
|
boolean |
contains(int x,
int y)
Returns true if the sprite's bounds contain the specified point, false if not.
|
void |
fastForward(long timeDelta)
Called when the appropriate media manager has been paused for some length of time and is
then unpaused.
|
int |
getHeight()
Returns the sprite's height in pixels.
|
int |
getOrientation()
Returns the sprite's orientation as one of the eight cardinal directions:
DirectionCodes.NORTH, DirectionCodes.NORTHEAST, etc. |
Path |
getPath()
Returns the path being followed by this sprite or null if the sprite is not following a path.
|
int |
getWidth()
Returns the sprite's width in pixels.
|
int |
getX()
Returns the sprite's x position in screen coordinates.
|
int |
getXOffset()
Returns the offset to the sprite's origin from the upper-left of the sprite's image.
|
int |
getY()
Returns the sprite's y position in screen coordinates.
|
int |
getYOffset()
Returns the offset to the sprite's origin from the upper-left of the sprite's image.
|
boolean |
hitTest(int x,
int y)
Returns true if the sprite's bounds contain the specified point, false if not.
|
boolean |
inside(Shape shape)
Returns whether the sprite is inside the given shape in pixel coordinates.
|
boolean |
intersects(Shape shape)
Returns whether the sprite's drawn rectangle intersects the given shape in pixel coordinates.
|
boolean |
isMoving()
Returns true if this sprite is currently following a path, false if it is not.
|
void |
move(Path path)
Set the sprite's active path and start moving it along its merry way.
|
void |
paint(Graphics2D gfx)
Called by the appropriate manager to request that the media render itself with the given
graphics context.
|
void |
paintPath(Graphics2D gfx)
Paint the sprite's path, if any, to the specified graphics context.
|
void |
pathBeginning()
Called by the active path when it begins.
|
void |
pathCompleted(long timestamp)
Called by the active path when it has completed.
|
void |
removeSpriteObserver(Object obs)
Remove a sprite observer.
|
void |
setLocation(int x,
int y)
Set the location.
|
void |
setOrientation(int orient)
Sprites have an orientation in one of the eight cardinal directions:
DirectionCodes.NORTH, DirectionCodes.NORTHEAST, etc. |
void |
tick(long tickStamp)
Called periodically by this media's manager to give it a chance to do its thing.
|
void |
viewLocationDidChange(int dx,
int dy)
Called by the
AbstractMediaManager when we are in a VirtualMediaPanel that
just scrolled. |
contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, getRenderOrder, init, intersects, intersects, invalidate, queueNotification, renderCompareTo, setRenderOrder, toStringpublic Sprite()
public Sprite(int width,
int height)
public int getX()
public int getY()
public int getXOffset()
public int getYOffset()
public int getWidth()
public int getHeight()
public void setOrientation(int orient)
DirectionCodes.NORTH, DirectionCodes.NORTHEAST, etc. Derived classes can
choose to override this member function and select a different set of images based on their
orientation, or they can ignore the orientation information.setOrientation in interface PathableDirectionCodespublic int getOrientation()
DirectionCodes.NORTH, DirectionCodes.NORTHEAST, etc.getOrientation in interface PathableDirectionCodespublic void setLocation(int x,
int y)
AbstractMediasetLocation in interface PathablesetLocation in class AbstractMediapublic void paint(Graphics2D gfx)
AbstractMediapaint in class AbstractMediapublic void paintPath(Graphics2D gfx)
gfx - the graphics context.public boolean contains(int x,
int y)
public boolean hitTest(int x,
int y)
public boolean inside(Shape shape)
public boolean intersects(Shape shape)
public boolean isMoving()
public void move(Path path)
path - the path to follow.public void cancelMove()
public Path getPath()
public void pathBeginning()
pathBeginning in interface Pathablepublic void pathCompleted(long timestamp)
pathCompleted in interface Pathablepublic void tick(long tickStamp)
AbstractMediatick in class AbstractMediatickStamp - a time stamp associated with this tick. Note: this is not obtained
from a call to System.currentTimeMillis() and cannot be compared to timestamps
obtained there from.public void fastForward(long timeDelta)
AbstractMediafastForward in class AbstractMediapublic void addSpriteObserver(Object obs)
obs - the sprite observer.public void removeSpriteObserver(Object obs)
public void viewLocationDidChange(int dx,
int dy)
AbstractMediaAbstractMediaManager when we are in a VirtualMediaPanel that
just scrolled.viewLocationDidChange in class AbstractMediaCopyright © 2015. All rights reserved.