visual.dynamic.described
Class AbstractSprite

java.lang.Object
  extended by visual.dynamic.described.AbstractSprite
All Implemented Interfaces:
MetronomeListener, Sprite, SimpleContent, TransformableContent
Direct Known Subclasses:
RuleBasedSprite, TweeningSprite

public abstract class AbstractSprite
extends java.lang.Object
implements Sprite

A Sprite is an "actor" on a Stage. In essence, a Sprite decorates a TransformableContent object, providing it with additional capabilities. Note: We don't immediately delegate since the content and the location/rotation/scale may change at any time and in any order. Instead, we set the location/rotation/scale before rendering.

See Also:
"The Design and Implementation of Multimedia Software © 2011"

Field Summary
protected  double angle
           
protected  boolean rotationPoint
           
protected  double rotationX
           
protected  double rotationY
           
protected  double scaleX
           
protected  double scaleY
           
protected  boolean visible
           
protected  double x
           
protected  double y
           
 
Constructor Summary
AbstractSprite()
          Default Constructor
 
Method Summary
 java.awt.geom.Rectangle2D getBounds2D()
          Returns a high precision bounding box of the transformed Content
 java.awt.geom.Rectangle2D getBounds2D(boolean ofTransformed)
          Returns a high precision bounding box of the Content either before or after it is transformed
protected abstract  TransformableContent getContent()
          Gets the (current) visual content for this Sprite This method is called by various setters and the render() method.
abstract  void handleTick(int time)
          Handle a tick event (required by MetronomeListener)
 boolean intersects(Sprite s)
          Does the bounding box of this Sprite intersect the bounding box of the given Sprite? (given their current state)
protected  void reinitialize()
          Initialize state variables
 void render(java.awt.Graphics g)
          Render this Sprite
 void setLocation(double x, double y)
          Set the location (on the Stage) of the Sprite
 void setRotation(double r)
          Set the rotation angle (the Sprite will rotate around its midpoint)
 void setRotation(double r, double x, double y)
          Set the rotation angle and point to rotate around
 void setScale(double s)
          Set the scaling (enlargement, reduction) of the Sprite
 void setScale(double sx, double sy)
          Set the scaling (enlargement, reduction) of the Sprite
 void setVisible(boolean v)
          Set the visibility of this Sprite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rotationPoint

protected boolean rotationPoint

visible

protected boolean visible

angle

protected double angle

rotationX

protected double rotationX

rotationY

protected double rotationY

scaleX

protected double scaleX

scaleY

protected double scaleY

x

protected double x

y

protected double y
Constructor Detail

AbstractSprite

public AbstractSprite()
Default Constructor

Method Detail

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D(boolean ofTransformed)
Returns a high precision bounding box of the Content either before or after it is transformed

Specified by:
getBounds2D in interface TransformableContent
Parameters:
ofTransformed - true to get the bounds of the transformed content
Returns:
The bounding box

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Returns a high precision bounding box of the transformed Content

Returns:
The bounding box

getContent

protected abstract TransformableContent getContent()
Gets the (current) visual content for this Sprite This method is called by various setters and the render() method.


handleTick

public abstract void handleTick(int time)
Handle a tick event (required by MetronomeListener)

Specified by:
handleTick in interface MetronomeListener
Parameters:
time - The current time (in milliseconds)

reinitialize

protected void reinitialize()
Initialize state variables


intersects

public boolean intersects(Sprite s)
Does the bounding box of this Sprite intersect the bounding box of the given Sprite? (given their current state)

Parameters:
s - The other Sprite
Returns:
true if the two intersect

render

public void render(java.awt.Graphics g)
Render this Sprite

Specified by:
render in interface SimpleContent
Parameters:
g - The rendering engine to use

setLocation

public void setLocation(double x,
                        double y)
Set the location (on the Stage) of the Sprite

Specified by:
setLocation in interface TransformableContent
Parameters:
x - The horizontal location
y - The vertical location

setRotation

public void setRotation(double r,
                        double x,
                        double y)
Set the rotation angle and point to rotate around

Specified by:
setRotation in interface TransformableContent
Parameters:
r - The new rotation angle
x - The x-coordinate of the point to rotate around
y - The y-coordinate of the point to rotate around

setRotation

public void setRotation(double r)
Set the rotation angle (the Sprite will rotate around its midpoint)

Parameters:
r - The new rotation angle

setScale

public void setScale(double sx,
                     double sy)
Set the scaling (enlargement, reduction) of the Sprite

Specified by:
setScale in interface TransformableContent
Parameters:
sx - The scale in the x-dimension
sy - The scale in the y-dimension

setScale

public void setScale(double s)
Set the scaling (enlargement, reduction) of the Sprite

Parameters:
s - The new scale

setVisible

public void setVisible(boolean v)
Set the visibility of this Sprite

Parameters:
v - true for visible, false for invisible


Design and Implementation of Multimedia Software, Jones and Bartlett Publishers