|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttipgame.Sprite
public class Sprite
this class provides a structure for representing sprites which have size, shape, orientation, and color. These sprites will appear when add to the AnimationCanvas. Sprites also optionally have a tracker which will update the Sprite's properties at each time interval.
| Field Summary | |
|---|---|
protected java.awt.Color |
color
the fill color of the shape, black by default |
private boolean |
destroy
true indicates the Sprite will be removed from the AnimationCanvas |
private boolean |
enabled
whether the sprite should be displayed and tracked |
private java.awt.geom.GeneralPath |
shape
shape should initially be centered at (0, 0) |
private java.awt.geom.GeneralPath |
shapeTransformed
transformed shape |
protected Tracker |
tracker
determines the generic movement of the sprite |
private java.awt.geom.AffineTransform |
transform
applied to the shape prior to drawing it |
private boolean |
useBoundingBox
use bounding box for bounce geometry |
private boolean |
visible
whether the sprite should be displayed. |
| Constructor Summary | |
|---|---|
Sprite()
initialize to an empty shape and the default values for scale, rotation, an rotation. |
|
Sprite(java.awt.Shape shape)
initializes to a given shape and the default values for scale and rotation. |
|
| Method Summary | |
|---|---|
void |
flipAlongHorizontalAxis()
flips along the horizontal axis. |
void |
flipAlongVerticalAxis()
flips along the vertical axis. |
java.awt.geom.Rectangle2D |
getBounds2D()
returns 2-D bounding box of sprites |
java.awt.Color |
getColor()
returns the fill color of the Sprite |
java.awt.geom.Point2D.Double |
getLocation()
the location of the shape as measured from its original location at (0, 0) |
static double |
getNormalVector(java.awt.Shape stationary,
java.awt.Shape moving)
Simulates the surface normal used for bouncing the moving object off of the stationary object. |
double |
getRotation()
gets the current amount of rotation in radians |
double |
getScale()
the scaling factor |
java.awt.Shape |
getShape()
gets the shape in its current position, size, and orientation |
Tracker |
getTracker()
gets the Tracker which has been attached to the Sprite |
boolean |
getUseBoundingBox()
|
boolean |
intersects(Sprite sprite)
determines if another Sprite intersects this Sprite |
protected boolean |
isDestroyed()
determines if the sprite should be removed from the AnimationCanvas |
boolean |
isEnabled()
determines the Sprite's ability to display and update |
boolean |
isVisible()
returns whether the Sprite is currently displayable |
void |
kill()
destroys the Sprite immediately |
protected void |
normalize()
resizes to be 1 by 1 and centers around origin (0, 0) |
void |
paint(java.awt.Graphics2D brush)
draws the shape in the proper location, orientation, and size |
protected void |
paintInternal(java.awt.Graphics2D brush)
provides a mechanism for enabling and visibility |
void |
rotate(double rotation)
sets the orienation with regard to the current orientation |
void |
scale(double scale)
scale with regard to the current scaling. |
void |
setColor(java.awt.Color c)
determines the fill color of the shape. |
void |
setEnabled(boolean able)
sets the Sprite's ability to display and update |
void |
setLocation(double x,
double y)
sets the location without regard to its current location |
void |
setLocation(java.awt.geom.Point2D.Double location)
sets the location without regard to its current location |
void |
setRotation(double rotation)
sets the orientation without regard to the current orientation |
void |
setScale(double scale)
sets the absolute scale without regard to its current value, must be nonzero |
void |
setShape(java.awt.Shape s)
sets shape to shape s |
void |
setTracker(Tracker t)
attaches the Tracker to this Sprite. |
void |
setUseBoundingBox(boolean box)
Sets the parameter which determines if the actual shape or its minimal bounding box is used in tests for intersection. |
void |
setVisible(boolean vis)
sets if the Sprite will be displayed when added to an AnimationCanvas |
void |
translate(java.awt.geom.Point2D.Double delta)
moves the shape wiht regard to its current location |
void |
update(double interval)
Calls advanceTime on the Sprite's Tracker (if the Tracker has been set). |
protected void |
updateInternal(double interval)
provides a mechanism for disabling Sprites |
private void |
updateShape()
updates shape of Sprite |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.awt.geom.GeneralPath shape
private java.awt.geom.GeneralPath shapeTransformed
private java.awt.geom.AffineTransform transform
protected java.awt.Color color
protected Tracker tracker
private boolean useBoundingBox
private boolean enabled
private boolean destroy
private boolean visible
| Constructor Detail |
|---|
public Sprite()
public Sprite(java.awt.Shape shape)
shape - | Method Detail |
|---|
public void kill()
protected boolean isDestroyed()
public void setUseBoundingBox(boolean box)
box - true indicates a bounding box should be used, false indicates
the actual shape should be usedpublic boolean getUseBoundingBox()
public void setShape(java.awt.Shape s)
s - protected void normalize()
public void setColor(java.awt.Color c)
c - the fill colorpublic void setTracker(Tracker t)
t - the Tracker which will act upon this Spritepublic java.awt.Color getColor()
public Tracker getTracker()
public void setScale(double scale)
scale - the new scaleprivate void updateShape()
protected void updateInternal(double interval)
public void update(double interval)
public void scale(double scale)
scale - the factor by which to change the current scale, must be
nonzeropublic void setRotation(double rotation)
rotation - the new orientation in radians counter-clockwise for the
original orientationpublic void rotate(double rotation)
rotation - the additional rotation in radianspublic double getScale()
public java.awt.geom.Point2D.Double getLocation()
public void setLocation(java.awt.geom.Point2D.Double location)
location - the new location
public void setLocation(double x,
double y)
x - the horizontal locationy - the vertical locationpublic void translate(java.awt.geom.Point2D.Double delta)
delta - the amount and direction to move the shape from its current
location
public static double getNormalVector(java.awt.Shape stationary,
java.awt.Shape moving)
stationary - the object not in motionmoving - the object that will bounce off
of the stationary object
public double getRotation()
public boolean isVisible()
public void setVisible(boolean vis)
vis - true indicates to display, false to hideprotected void paintInternal(java.awt.Graphics2D brush)
brush - the Graphics2D to draw onpublic void paint(java.awt.Graphics2D brush)
brush - the Graphics used to draw the shapepublic java.awt.Shape getShape()
public java.awt.geom.Rectangle2D getBounds2D()
public boolean intersects(Sprite sprite)
sprite - another Sprite
public boolean isEnabled()
public void setEnabled(boolean able)
able - true indicates the Sprite can display and update, false
otherwisepublic void flipAlongVerticalAxis()
public void flipAlongHorizontalAxis()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||