PulpCore

pulpcore.sprite
Class Group

java.lang.Object
  extended by pulpcore.sprite.Sprite
      extended by pulpcore.sprite.Group
All Implemented Interfaces:
PropertyListener
Direct Known Subclasses:
ScrollPane, Viewport

public class Group
extends Sprite

A container of Sprites.


Field Summary
 
Fields inherited from class pulpcore.sprite.Sprite
alpha, anchorX, anchorY, 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(int index, Sprite sprite)
          Inserts a Sprite to this Group at the specified position.
 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 findWithTag(Object tag)
          Finds the Sprite whose tag is equal to the specified tag (using tag.equals(sprite.getTag()).
 Sprite get(int index)
          Returns the sprite at the specified position in this group.
 CoreImage getBackBuffer()
           
 BlendMode getBackBufferBlendMode()
          Gets this Group's blend mode for rendering onto its back buffer.
protected  int getNaturalHeight()
          Gets the fixed-point value of the Sprite's natural height.
protected  int getNaturalWidth()
          Gets the fixed-point value of the Sprite's natural width.
 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.
 boolean isAncestorOf(Sprite sprite)
          Returns true if this Group is an ancestor of the specified Sprite.
 boolean isOverflowClipped()
          Returns true if sprites inside this Group are not visible outside the natural bounds of this Group.
 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 bounds (x, y, width, and height) 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 propertyChange(Property p)
          On a property change this Sprite is marked as dirty.
 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, getBlendMode, getCursor, getDirtyRect, getFilter, getLocalX, getLocalY, getParent, getPixelLevelChecks, getRoot, getScene2D, getTag, getViewX, getViewX, getViewY, getViewY, intersects, isDirty, isEnabled, isEnabledAndVisible, isMouseDoubleClicked, isMouseDown, isMouseHover, isMouseOver, isMousePressed, isMouseReleased, isMouseTripleClicked, isMouseWheelRotated, isOpaque, isPick, isPickEnabledAndVisible, isTransparent, move, move, move, move, move, move, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, removeFromParent, scale, scale, scale, scale, scale, scale, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, scaleTo, setAnchor, setAnchor, setBlendMode, setCursor, setDirty, setFilter, setLocation, setLocation, setSize, setSize, setTag, 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

isOverflowClipped

public boolean isOverflowClipped()
Returns true if sprites inside this Group are not visible outside the natural bounds of this Group. The default implementation returns true if the Group has a back buffer.

See Also:
getNaturalWidth(), getNaturalHeight()

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.


isAncestorOf

public boolean isAncestorOf(Sprite sprite)
Returns true if this Group is an ancestor of the specified Sprite.


findWithTag

public Sprite findWithTag(Object tag)
Finds the Sprite whose tag is equal to the specified tag (using tag.equals(sprite.getTag()). Returns null if the specified tag is null, or if no Sprite with the specified tag is found.


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.


add

public void add(int index,
                Sprite sprite)
Inserts a Sprite to this Group at the specified position. The Sprite at the current position (if any) and any subsequent Sprites are moved up in the z-order (adds one to their indices).

If the index is less than zero, the sprite is inserted at position zero (the bottom in the z-order). If the index is greater than or equal to size(), the sprite is inserted at position size() (the top in the z-order).


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 bounds (x, y, width, and height) 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.

getBackBuffer

public CoreImage getBackBuffer()

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()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural width. Subclasses will override this method to specify the natural width. The natural width is the width of the Sprite if no scaling is applied - for an ImageSprite, the natural width is the width of the image.

Overrides:
getNaturalWidth in class Sprite

getNaturalHeight

protected int getNaturalHeight()
Description copied from class: Sprite
Gets the fixed-point value of the Sprite's natural height. Subclasses will override this method to specify the natural height. The natural height is the height of the Sprite if no scaling is applied - for an ImageSprite, the natural height is the height of the image.

Overrides:
getNaturalHeight in class Sprite

propertyChange

public void propertyChange(Property p)
Description copied from class: Sprite
On a property change this Sprite is marked as dirty.

Specified by:
propertyChange in interface PropertyListener
Overrides:
propertyChange in class Sprite
Parameters:
p - the property whose value has changed.

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 final void drawSprite(CoreGraphics g)
Description copied from class: Sprite
Draws the sprite. The graphic context's alpha is set to this sprite's alpha, 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.

This method may be called multiple times for each dirty rectangle. The clip of the graphics context will be set to the current dirty rectangle.

When the contents of this sprite change (in another words, the graphic output of this method will be different from the last time it is called), subclasses should call setDirty(true).

Implementors should not save a reference to the graphics context as it can change between calls to this method.

Specified by:
drawSprite in class Sprite

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.