|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectfang.Sprite
fang.CompositeSprite
public class CompositeSprite
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).
| 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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static Color debugCrosshairsColor
| Constructor Detail |
|---|
public CompositeSprite()
| Method Detail |
|---|
public void addSprite(Sprite s)
s - the sprite to addpublic void addSprite(Sprite... sprite)
s - the sprite to addpublic void advanceTime(double timeInterval)
advanceTime in class SpritetimeInterval - public boolean contains(Sprite sprite)
sprite - the sprite to check for membership
public List<Sprite> getAllSprites()
List of fang.core.Sprite that make up this
composite. The value returned
CompositeSprite.public Location2D getFrameLocation(Location2D outside)
outside - the position in the canvas coordinate system
public Location2D getFrameLocation(double outsideX,
double outsideY)
public Location2D getRealLocation(Location2D inside)
inside - the position relative to this group
public Location2D getRealLocation(double insideX,
double insideY)
public Shape getShape()
Shape of a CompositeSprite is
the union of the shapes of the subsprites.
getShape in class Sprite
public boolean intersects(double x,
double y)
intersects in class Spritepoint - the point to test
public boolean intersects(Sprite other)
intersects in class Spriteother - another Sprite
public void paintShape(Graphics2D brush)
paintShape in class Spritebrush - the Graphics used to draw the shapepublic void removeSprite(Sprite s)
s - the sprite to removepublic void update()
update in class Spriteprotected void drawDebugShapes(Graphics2D brush)
Sprite
drawDebugShapes in class Spritebrush - The graphics context in which to draw the box
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||