fang
Class CompositeSpriteOld

java.lang.Object
  extended by fang.Sprite
      extended by fang.CompositeSpriteOld
Direct Known Subclasses:
MultiShapeSprite

public class CompositeSpriteOld
extends Sprite

This class extend the base Sprite class in order to allow multiple colors and shapes in a single sprite. Note: this is a new class which has not been fully tested. Testing is currently underway. Please email any bug reports to bugs@fangengine.org.

Author:
Jam Jenkins

Field Summary
 
Fields inherited from class fang.Sprite
color, config, DEBUG_BOUNDING_BOX, DEBUG_INTERSECTS, debugBoundingBoxColor, image, optimizeForBitmap, shape, tracker, transform
 
Constructor Summary
CompositeSpriteOld()
           
 
Method Summary
 void addShape(Shape shape, Color color)
          adds the shape with a given color to this MultiShapeSprite.
 void addShape(Shape shape, Color color, boolean allowRescale)
          adds the shape with a given color to this MultiShapeSprite.
 void addSprite(Sprite sprite)
           
 void addSprite(Sprite sprite, String name)
           
 Color getColor(Shape shape)
          gets the color assigned to this shape.
 Color getColor(String name)
          gets the color assigned to the shape with this name.
 String[] getNamesOfIntersecting(Sprite sprite)
          gets the names of the intersecting shapes
 Shape getShape()
          gets the shape of this sprite in its current orientation, position and size
 Shape getShape(String name)
          gets the particular shape in the same location, orientation, and scale in which it was originally added
 Shape[] getShapesIntersecting(Sprite sprite)
          gets all of the shapes intersecting with another sprite.
 boolean hasShape(Shape shape)
           
 boolean hasShape(String name)
           
 boolean intersects(Sprite sprite)
          determines if this sprite intersects with the other sprite
 boolean intersects(Sprite sprite, Shape shape)
          determines if a particular shape intersects with another sprite
 boolean intersects(Sprite sprite, String name)
          determines if a particular shape intersects with another sprite
 boolean isVisible(Shape shape)
          determines if the shape is being displayed
 boolean isVisible(String name)
          determines if the named shape is being displayed
 void moveToBottom(Shape shape)
          moves the indicated shape to the bottom of the stack of shapes
 void moveToBottom(String name)
          moves the indicated shape to the bottom of the stack of shapes
 void moveToTop(Shape shape)
          moves the indicated shape to the top of the stack of shapes
 void moveToTop(String name)
          moves the indicated shape to the top of the stack of shapes
 void paint(Graphics2D brush)
          draws all of the visible shapes in their given colors
 void removeShape(Shape shape)
          removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.
 void removeShape(Shape shape, boolean allowRescale)
          removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.
 void removeShape(String name)
          removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.
 void removeShape(String name, boolean allowRescale)
          removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.
 void setColor(Shape shape, Color color)
          sets the color of a shape
 void setColor(String name, Color color)
          sets the color of a shape given its name
 void setShapeName(String name, Shape shape)
          gives a shape a name.
 void setVisible(Shape shape, boolean vis)
          sets the shape's visibility
 void setVisible(String name, boolean vis)
          sets the named shape's visibility
 
Methods inherited from class fang.Sprite
addTransformer, advanceTime, bounceOffOf, disableTransformer, drawDebugShapes, 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, intersects, isDestroyed, isEnabled, isVisible, normalize, paintInternal, paintShape, 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, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeSpriteOld

public CompositeSpriteOld()
Method Detail

intersects

public boolean intersects(Sprite sprite)
determines if this sprite intersects with the other sprite

Overrides:
intersects in class Sprite
Parameters:
sprite - the other sprite
Returns:
true if this sprite intersects with the other sprite, false otherwise

getShapesIntersecting

public Shape[] getShapesIntersecting(Sprite sprite)
gets all of the shapes intersecting with another sprite. Calling this method may be slow if there are many shapes in the sprite.

Parameters:
sprite - the sprite which may or may not be intersecting
Returns:
the array of sprites which intersect

getNamesOfIntersecting

public String[] getNamesOfIntersecting(Sprite sprite)
gets the names of the intersecting shapes

Parameters:
sprite - the other sprite to check for intersection with
Returns:
the array of names of shapes which are intersecting with the other sprite

intersects

public boolean intersects(Sprite sprite,
                          String name)
determines if a particular shape intersects with another sprite

Parameters:
sprite - the other sprite
name - the name of the shape to check
Returns:
true if the shape indicated intersects, false otherwise

intersects

public boolean intersects(Sprite sprite,
                          Shape shape)
determines if a particular shape intersects with another sprite

Parameters:
sprite - the other sprite
shape - the shape to check
Returns:
true if the shape indicated intersects, false otherwise

setShapeName

public void setShapeName(String name,
                         Shape shape)
gives a shape a name. This method is added for convenience in later identifying the component shapes which make up this MultiShapeSprite

Parameters:
name - the identifier for the shape
shape - the shape to identify

getShape

public Shape getShape(String name)
gets the particular shape in the same location, orientation, and scale in which it was originally added

Parameters:
name - the identifier for the shape to retrieve
Returns:
the shape corresponding with this name

getShape

public Shape getShape()
gets the shape of this sprite in its current orientation, position and size

Overrides:
getShape in class Sprite
Returns:
the current shape

getColor

public Color getColor(Shape shape)
gets the color assigned to this shape. Returns null if the shape is not part of this MultiShapeSprite.

Parameters:
shape - the shape to check
Returns:
the color of the shape

getColor

public Color getColor(String name)
gets the color assigned to the shape with this name. Returns null if no shape is associated with the given name.

Parameters:
name - the name of the shape to check
Returns:
the color of the shape

setColor

public void setColor(String name,
                     Color color)
sets the color of a shape given its name

Parameters:
name - the name of the shape
color - the color for the shape

setColor

public void setColor(Shape shape,
                     Color color)
sets the color of a shape

Parameters:
shape - the shape to color
color - the color for the shape

addShape

public void addShape(Shape shape,
                     Color color,
                     boolean allowRescale)
adds the shape with a given color to this MultiShapeSprite. When the shape is added, it may increase the bounds of the total shape. If allowRescale is true, then this sprite will rescale to keep the display of the sprite consistently sized by changing the scale if necessary. If allowRescale is false, the appearance of the existing shapes may shrink when a shape is added which increases the bounds of the current sprite in order to keep the scale consistent.

Parameters:
shape - the shape to add
color - the color of the shape
allowRescale - true allows the scale to change in order to maintain a consistent appearance, false indicates to maintain a consistent scale and possible shrink the appearance

addSprite

public void addSprite(Sprite sprite)

addSprite

public void addSprite(Sprite sprite,
                      String name)

addShape

public void addShape(Shape shape,
                     Color color)
adds the shape with a given color to this MultiShapeSprite. When the shape is added, the size of the original sprite will appear unchanged even though the scale of this sprite may need to be changed in order to keep the display consistently sized.

Parameters:
shape - the shape to add
color - the color of the shape

removeShape

public void removeShape(String name)
removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.

Parameters:
name - the name of the shape to remove

removeShape

public void removeShape(Shape shape)
removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.

Parameters:
shape - the shape to remove

removeShape

public void removeShape(String name,
                        boolean allowRescale)
removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.

Parameters:
name - the name of the shape to remove
allowRescale - true indicates that the sprite may be resized in order to provide for a consistent appearance, false indicates the scale should remain consistent and the appearance of the remaining shapes may appear larger or smaller.

isVisible

public boolean isVisible(String name)
determines if the named shape is being displayed

Parameters:
name - the name of the shape to check
Returns:
true if the named shape is displayed when this sprite is drawn, false otherwise

isVisible

public boolean isVisible(Shape shape)
determines if the shape is being displayed

Parameters:
shape - the shape to check
Returns:
true if the shape is displayed when this sprite is drawn, false otherwise

setVisible

public void setVisible(String name,
                       boolean vis)
sets the named shape's visibility

Parameters:
name - the name of the shape to alter
vis - true indicates the shape should be drawn, false for invisibility

setVisible

public void setVisible(Shape shape,
                       boolean vis)
sets the shape's visibility

Parameters:
shape - the shape to alter
vis - true indicates the shape should be drawn, false for invisibility

removeShape

public void removeShape(Shape shape,
                        boolean allowRescale)
removes the shape from the MultiShapeSprite, possibly rescaling in order for the sprite to maintain a consistent appearance.

Parameters:
shape - the the shape to remove
allowRescale - true indicates that the sprite may be resized in order to provide for a consistent appearance, false indicates the scale should remain consistent and the appearance of the remaining shapes may appear larger or smaller.

paint

public void paint(Graphics2D brush)
draws all of the visible shapes in their given colors

Overrides:
paint in class Sprite
Parameters:
brush - the graphics used to draw with

hasShape

public boolean hasShape(String name)

hasShape

public boolean hasShape(Shape shape)

moveToBottom

public void moveToBottom(String name)
moves the indicated shape to the bottom of the stack of shapes

Parameters:
name - the name of the shape to move

moveToBottom

public void moveToBottom(Shape shape)
moves the indicated shape to the bottom of the stack of shapes

Parameters:
shape - the shape to move

moveToTop

public void moveToTop(String name)
moves the indicated shape to the top of the stack of shapes

Parameters:
name - the name of the shape to move

moveToTop

public void moveToTop(Shape shape)
moves the indicated shape to the top of the stack of shapes

Parameters:
shape - the shape to move