PulpCore

pulpcore.sprite
Class Group

java.lang.Object
  extended by pulpcore.sprite.Sprite
      extended by pulpcore.sprite.Group
All Implemented Interfaces:
PropertyListener

public class Group
extends Sprite

A container of Sprites.


Field Summary
 
Fields inherited from class pulpcore.sprite.Sprite
alpha, angle, CENTER, DEFAULT, EAST, enabled, height, NORTH, NORTH_EAST, NORTH_WEST, pixelSnapping, SOUTH, SOUTH_EAST, SOUTH_WEST, visible, WEST, width, x, y
 
Constructor Summary
Group()
           
Group(double x, double y)
           
Group(double x, double y, double width, double height)
           
Group(int x, int y)
           
Group(int x, int y, int width, int height)
           
 
Method Summary
 void add(Sprite sprite)
          Adds a Sprite to this Group.
 boolean contains(Sprite sprite)
          Returns true if this Group contains the specified Sprite.
 void createBackBuffer()
          Creates a back buffer for this Group.
 void createBackBuffer(BlendMode blendMode)
          Creates a back buffer for this Group, and sets the blend mode for rendering onto the back buffer.
protected  void drawSprite(CoreGraphics g)
          Draws the sprite.
 Sprite get(int index)
          Returns the sprite at the specified position in this group.
protected  int getAnchorX()
           
protected  int getAnchorY()
           
 BlendMode getBackBufferBlendMode()
          Gets this Group's blend mode for rendering onto its back buffer.
protected  int getNaturalHeight()
           
protected  int getNaturalWidth()
           
 int getNumSprites()
          Returns the number of sprites in this group and all child groups (not counting child Groups themselves).
 int getNumVisibleSprites()
          Returns the number of visible sprites in this group and all child groups (not counting child Groups themselves).
 ArrayList getRemovedSprites()
          Gets a list of all of the Sprites in this Group that were removed since the last call to this method.
 boolean hasBackBuffer()
          Checks if this Group has a back buffer.
 Iterator iterator()
          Returns an Iterator of the Sprites in this Group (in proper sequence).
 void moveDown(Sprite sprite)
          Moves the specified Sprite down in z-order, swapping places with the first Sprite that appears below it.
 void moveToBottom(Sprite sprite)
          Moves the specified Sprite to the bottom of the z-order, so that all the other Sprites currently in this Group appear above it.
 void moveToTop(Sprite sprite)
          Moves the specified Sprite to the top of the z-order, so that all the other Sprites currently in this Group appear underneath it.
 void moveUp(Sprite sprite)
          Moves the specified Sprite up in z-order, swapping places with the first Sprite that appears above it.
 void pack()
          Packs this group so that its dimensions match the area covered by its children.
 Sprite pick(int viewX, int viewY)
          Finds the top-most sprite at the specified location, or null if none is found.
 Sprite pickEnabledAndVisible(int viewX, int viewY)
          Finds the top-most sprite that is enabled and visible at the specified location, or null if none is found.
 void remove(Sprite sprite)
          Removes a Sprite from this Group.
 void removeAll()
          Removes all Sprites from this Group.
 void removeBackBuffer()
          Removes this Group's back buffer.
 void setBackBufferBlendMode(BlendMode backBufferBlendMode)
          Sets this Group's blend mode for rendering onto its back buffer.
 int size()
          Returns the number of sprites in this group.
 void update(int elapsedTime)
          Updates all of this Sprite's properties.
 
Methods inherited from class pulpcore.sprite.Sprite
bindLocationTo, bindSizeTo, clearCursor, clearDirtyRect, contains, draw, getAnchor, getBlendMode, getCursor, getDirtyRect, getLocalX, getLocalY, getParent, getPixelLevelChecks, getRoot, getScene2D, getViewX, getViewX, getViewY, getViewY, intersects, isDirty, isEnabled, isEnabledAndVisible, isMouseDoubleClicked, isMouseDown, isMouseHover, isMouseOver, isMousePressed, isMouseReleased, isMouseTripleClicked, isMouseWheelRotated, isPick, isPickEnabledAndVisible, isTransparent, move, move, move, move, move, move, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, propertyChange, scale, scale, scale, scale, scale, scale, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, setAnchor, setBlendMode, setCursor, setDirty, setLocation, setLocation, setSize, setSize, translate, translate, updateDirtyRect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Group

public Group()

Group

public Group(int x,
             int y)

Group

public Group(int x,
             int y,
             int width,
             int height)

Group

public Group(double x,
             double y)

Group

public Group(double x,
             double y,
             double width,
             double height)
Method Detail

iterator

public Iterator iterator()
Returns an Iterator of the Sprites in this Group (in proper sequence). The iterator provides a snapshot of the state of the list when the iterator was constructed. No synchronization is needed while traversing the iterator. The iterator does NOT support the remove method.

Returns:
The iterator.

size

public int size()
Returns the number of sprites in this group. This includes child groups but not the children of those groups.


get

public Sprite get(int index)
Returns the sprite at the specified position in this group. Returns null if the index is out of range (index < 0 || index >= size()).


contains

public boolean contains(Sprite sprite)
Returns true if this Group contains the specified Sprite.


pick

public Sprite pick(int viewX,
                   int viewY)
Finds the top-most sprite at the specified location, or null if none is found. All sprites in this Group and any child Groups are searched until a sprite is found. This method never returns a Group.

Parameters:
viewX - x-coordinate in view space.
viewY - y-coordinate in view space.
Returns:
The top-most sprite at the specified location, or null if none is found.

pickEnabledAndVisible

public Sprite pickEnabledAndVisible(int viewX,
                                    int viewY)
Finds the top-most sprite that is enabled and visible at the specified location, or null if none is found. All sprites in this Group and any child Groups are searched until a sprite is found. This method never returns a Group.

This Group or it's ancestors (if any) are not checked if they are enabled or visible.

This method is useful for finding a sprite to use to set the cursor or take mouse input from.

Parameters:
viewX - x-coordinate in view space
viewY - y-coordinate in view space
Returns:
The top-most sprite that is enabled and visible at the specified location, or null if none is found.

getNumSprites

public int getNumSprites()
Returns the number of sprites in this group and all child groups (not counting child Groups themselves).


getNumVisibleSprites

public int getNumVisibleSprites()
Returns the number of visible sprites in this group and all child groups (not counting child Groups themselves).


add

public void add(Sprite sprite)
Adds a Sprite to this Group. The Sprite is added so it appears above all other sprites in this Group. If this Sprite already belongs to a Group, it is first removed from that Group before added to this one.


remove

public void remove(Sprite sprite)
Removes a Sprite from this Group.


removeAll

public void removeAll()
Removes all Sprites from this Group.


moveToTop

public void moveToTop(Sprite sprite)
Moves the specified Sprite to the top of the z-order, so that all the other Sprites currently in this Group appear underneath it. If the specified Sprite is not in this Group, or the Sprite is already at the top, this method does nothing.


moveToBottom

public void moveToBottom(Sprite sprite)
Moves the specified Sprite to the bottom of the z-order, so that all the other Sprites currently in this Group appear above it. If the specified Sprite is not in this Group, or the Sprite is already at the bottom, this method does nothing.


moveUp

public void moveUp(Sprite sprite)
Moves the specified Sprite up in z-order, swapping places with the first Sprite that appears above it. If the specified Sprite is not in this Group, or the Sprite is already at the top, this method does nothing.


moveDown

public void moveDown(Sprite sprite)
Moves the specified Sprite down in z-order, swapping places with the first Sprite that appears below it. If the specified Sprite is not in this Group, or the Sprite is already at the bottom, this method does nothing.


getRemovedSprites

public ArrayList getRemovedSprites()
Gets a list of all of the Sprites in this Group that were removed since the last call to this method.

This method is used by Scene2D to implement dirty rectangles.


pack

public void pack()
Packs this group so that its dimensions match the area covered by its children. If this Group has a back buffer, the back buffer is resized if necessary.


createBackBuffer

public void createBackBuffer()
Creates a back buffer for this Group.

If this Group was created with a dimension (constructors Group(int,int,int,int) or Group(double,double,double,double) or has a dimension after calling pack(), then the back buffer has the same dimensions of this Group. Otherwise, the back buffer has the same dimensions of the Stage.


createBackBuffer

public void createBackBuffer(BlendMode blendMode)
Creates a back buffer for this Group, and sets the blend mode for rendering onto the back buffer.

If this Group was created with a dimension (constructors Group(int,int,int,int) or Group(double,double,double,double) or has a dimension after calling pack(), then the back buffer has the same dimensions of this Group. Otherwise, the back buffer has the same dimensions of the Stage.


hasBackBuffer

public boolean hasBackBuffer()
Checks if this Group has a back buffer.

Returns:
true if this Group has a back buffer.

removeBackBuffer

public void removeBackBuffer()
Removes this Group's back buffer.


setBackBufferBlendMode

public void setBackBufferBlendMode(BlendMode backBufferBlendMode)
Sets this Group's blend mode for rendering onto its back buffer.

Parameters:
backBufferBlendMode - the blend mode.

getBackBufferBlendMode

public BlendMode getBackBufferBlendMode()
Gets this Group's blend mode for rendering onto its back buffer.

Returns:
the blend mode.

getNaturalWidth

protected int getNaturalWidth()
Overrides:
getNaturalWidth in class Sprite

getNaturalHeight

protected int getNaturalHeight()
Overrides:
getNaturalHeight in class Sprite

getAnchorX

protected int getAnchorX()
Overrides:
getAnchorX in class Sprite
Returns:
the fixed-point x anchor.

getAnchorY

protected int getAnchorY()
Overrides:
getAnchorY in class Sprite
Returns:
the fixed-point y anchor.

update

public void update(int elapsedTime)
Description copied from class: Sprite
Updates all of this Sprite's properties. Subclasses that override this method should call super.update().

Overrides:
update in class Sprite

drawSprite

protected void drawSprite(CoreGraphics g)
Description copied from class: Sprite
Draws the sprite. The graphic context's alpha is set to this sprite, and it's translation is offset by this sprite's location. This method is not called if the sprite is not visible or it's alpha is less than or equal to zero.

Specified by:
drawSprite in class Sprite

PulpCore

Copyright © 2007-2008 Interactive Pulp, LLC.