fang
Class CompositeSprite

java.lang.Object
  extended by fang.Sprite
      extended by fang.CompositeSprite
Direct Known Subclasses:
ButtonSprite

public class CompositeSprite
extends Sprite

A CompositeSprite that contains a group of sprites; individual sprites are positioned relative to the origin of the composite (they can be translated, rotate, or scaled relative to the CompositeSprites origin and scale). The entire group is then treated as a single sprite so it can be translated, rotated, or scaled as a unit. When the CompositeSprite is created, it has an origin just like a fang.core.Game: the origin is in the center of the sprite; this is different than the screen (where the center of the screen is at (0.5, 0.5)) but this makes it easier to picture where and how the composite sprite will be positioned and will rotate. As sprites are added to the CompositeSprite, their position, rotation, and scale are relative to the CompositeSprite's origin. Individual elements in a CompositeSprite can be referred to individually and moved/rotated/scaled relative to the whole sprite. The CompositeSprite can also be moved, rotated, scaled relative to the game canvas (assuming it has been added to the canvas). Visibility is handled at both the composite and subsprite levels: If the composite is visible, then the subsprites that are visible are drawn; if the composite is not visible, then none of the subsprites are drawn. Like the game canvas, the range of coordinates is effectively unbounded though only the portion scaled to fit on the screen is actually seen. Note that the location of the CompositeSprite (and the center of rotation for the whole sprite) is (0.0, 0.0) in terms of the CompositeSprite's coordinate system. This is so that a scale 1.0 sprite with no rotation and a location of (0.5, 0.5) will be centered on the screen (and coordinates on the sprite will be offset from those on the screen by 0.5 in each dimension).

Author:
Jam Jenkins, Robert C. Duvall, Brian C. Ladd

Field Summary
protected static Color debugCrosshairsColor
           
 
Fields inherited from class fang.Sprite
color, config, DEBUG_BOUNDING_BOX, DEBUG_INTERSECTS, debugBoundingBoxColor, image, optimizeForBitmap, shape, tracker, transform
 
Constructor Summary
CompositeSprite()
           
 
Method Summary
 void addSprite(Sprite... sprite)
          adds all the given sprites to this group
 void addSprite(Sprite s)
          adds a sprite to this group
 void advanceTime(double timeInterval)
          make the tracker act.
 boolean contains(Sprite sprite)
          determines if the sprite given as a parameter is part of this group.
protected  void drawDebugShapes(Graphics2D brush)
          Draw debug shapes.
 List<Sprite> getAllSprites()
          Get an List of fang.core.Sprite that make up this composite.
 Location2D getFrameLocation(double outsideX, double outsideY)
           
 Location2D getFrameLocation(Location2D outside)
          given a point in the canvas coordinate system, this method calculates where that point would currently be relative to this group
 Location2D getRealLocation(double insideX, double insideY)
           
 Location2D getRealLocation(Location2D inside)
          given a point relative to the center of this group, this method calculates where that point would currently be in the canvas coordinate system
 Shape getShape()
          The shape of the composite sprite, scaled and transformed appropriately.
 boolean intersects(double x, double y)
          determines if a point is within the sprite's shape
 boolean intersects(Sprite other)
          determines if another Sprite intersects this Sprite.
 void paintShape(Graphics2D brush)
          draws all added sprites in the proper location, orientation, and size
 void removeSprite(Sprite s)
          removes a sprite from this group.
 void update()
          Updates the Sprite's location, size, and orientation are determined using the Tracker.
 
Methods inherited from class fang.Sprite
addTransformer, bounceOffOf, disableTransformer, enableTransformer, forward, getBlurLength, getBounds2D, getColor, getDebug, getDebugBoundingBoxColor, getDefaultColor, getHeight, getLocation, getMaxX, getMaxY, getMinX, getMinY, getNormalVector, getNormalVector, getOptimizedForBitmap, getOrientation, getOrientationDegrees, getOrientationRadians, getOrientationRevolutions, getRotation, getRotationDegrees, getRotationRadians, getRotationRevolutions, getScale, getSize, getTracker, getUseBoundingBox, getWidth, getX, getY, hasTracker, hide, intersects, intersects, intersects, isDestroyed, isEnabled, isVisible, normalize, paint, paintInternal, removeAllTrackers, removeFromCanvas, removeTransformer, rotate, rotateDegrees, rotateRadians, rotateRevolutions, scale, setAbsoluteShape, setBlurLength, setColor, setDebug, setDebugBoundingBoxColor, setDebugBrush, setDefaultColor, setEnabled, setLocation, setLocation, setLocation, setOptimizedForBitmap, setOrientation, setOrientationDegrees, setOrientationRadians, setOrientationRevolutions, setRotation, setRotationDegrees, setRotationRadians, setRotationRevolutions, setScale, setShape, setSize, setTracker, setUseBoundingBox, setVisible, setX, setY, show, translate, translate, translate, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugCrosshairsColor

protected static Color debugCrosshairsColor
Constructor Detail

CompositeSprite

public CompositeSprite()
Method Detail

addSprite

public void addSprite(Sprite s)
adds a sprite to this group

Parameters:
s - the sprite to add

addSprite

public void addSprite(Sprite... sprite)
adds all the given sprites to this group

Parameters:
s - the sprite to add

advanceTime

public void advanceTime(double timeInterval)
make the tracker act.

Overrides:
advanceTime in class Sprite
Parameters:
timeInterval -

contains

public boolean contains(Sprite sprite)
determines if the sprite given as a parameter is part of this group.

Parameters:
sprite - the sprite to check for membership
Returns:
true if the sprite is part of the group, false otherwise

getAllSprites

public List<Sprite> getAllSprites()
Get an List of fang.core.Sprite that make up this composite. The value returned

Returns:
the ArrayList containing all of the sprites in this CompositeSprite.

getFrameLocation

public Location2D getFrameLocation(Location2D outside)
given a point in the canvas coordinate system, this method calculates where that point would currently be relative to this group

Parameters:
outside - the position in the canvas coordinate system
Returns:
the position relative to this group

getFrameLocation

public Location2D getFrameLocation(double outsideX,
                                   double outsideY)

getRealLocation

public Location2D getRealLocation(Location2D inside)
given a point relative to the center of this group, this method calculates where that point would currently be in the canvas coordinate system

Parameters:
inside - the position relative to this group
Returns:
the corresponding position in the canvas coordinate system

getRealLocation

public Location2D getRealLocation(double insideX,
                                  double insideY)

getShape

public Shape getShape()
The shape of the composite sprite, scaled and transformed appropriately. Note that the Shape of a CompositeSprite is the union of the shapes of the subsprites.

Overrides:
getShape in class Sprite
Returns:
the shape

intersects

public boolean intersects(double x,
                          double y)
determines if a point is within the sprite's shape

Overrides:
intersects in class Sprite
Parameters:
point - the point to test
Returns:
true if the point is in the shape, false otherwise

intersects

public boolean intersects(Sprite other)
determines if another Sprite intersects this Sprite. Intersection is a geometric property of the sprites and does not depend on whether the sprites are on the canvas or visible.

Overrides:
intersects in class Sprite
Parameters:
other - another Sprite
Returns:
true if the other Sprite intersects this Sprite, false if there is no intersection

paintShape

public void paintShape(Graphics2D brush)
draws all added sprites in the proper location, orientation, and size

Overrides:
paintShape in class Sprite
Parameters:
brush - the Graphics used to draw the shape

removeSprite

public void removeSprite(Sprite s)
removes a sprite from this group. If the sprite is not part of this group, the call is ignored and no exception is thrown.

Parameters:
s - the sprite to remove

update

public void update()
Updates the Sprite's location, size, and orientation are determined using the Tracker. If overridden, this method must not add or remove sprites from the canvas. If adding or removing sprites is desired, schedule this action to occur zero seconds from now by creating an alarm which performs the desired adding or removing.

Overrides:
update in class Sprite

drawDebugShapes

protected void drawDebugShapes(Graphics2D brush)
Description copied from class: Sprite
Draw debug shapes. This method draws the bounding box.

Overrides:
drawDebugShapes in class Sprite
Parameters:
brush - The graphics context in which to draw the box