com.badlogic.gdx.scenes.scene2d
Class Group

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.Group
All Implemented Interfaces:
Cullable
Direct Known Subclasses:
WidgetGroup

public class Group
extends Actor
implements Cullable

2D scene graph node that may contain other actors.

Actors have a z-order equal to the order they were inserted into the group. Actors inserted later will be drawn on top of actors added earlier. Touch events that hit more than one actor are distributed to topmost actors first.

Author:
mzechner, Nathan Sweet

Constructor Summary
Group()
           
 
Method Summary
 void act(float delta)
          Updates the actor based on time.
 void addActor(Actor actor)
          Adds an actor as a child of this group.
 void addActorAfter(Actor actorAfter, Actor actor)
          Adds an actor as a child of this group, immediately after another child actor.
 void addActorAt(int index, Actor actor)
          Adds an actor as a child of this group, at a specific index.
 void addActorBefore(Actor actorBefore, Actor actor)
          Adds an actor as a child of this group, immediately before another child actor.
 void clear()
          Removes all children, actions, and listeners from this group.
 void clearChildren()
          Removes all actors from this group.
 void draw(Batch batch, float parentAlpha)
          Draws the group and its children.
 Actor findActor(String name)
          Returns the first actor found with the specified name.
 SnapshotArray<Actor> getChildren()
          Returns an ordered list of child actors in this group.
 boolean hasChildren()
           
 Actor hit(float x, float y, boolean touchable)
          Returns the deepest actor that contains the specified point and is touchable and visible, or null if no actor was hit.
 boolean isTransform()
           
 Vector2 localToDescendantCoordinates(Actor descendant, Vector2 localCoords)
          Converts coordinates for this group to those of a descendant actor.
 void print()
          Prints the actor hierarchy recursively for debugging purposes.
 boolean removeActor(Actor actor)
          Removes an actor from this group.
 void setCullingArea(Rectangle cullingArea)
          Children completely outside of this rectangle will not be drawn.
 void setTransform(boolean transform)
          When true (the default), the Batch is transformed so children are drawn in their parent's coordinate system.
 boolean swapActor(Actor first, Actor second)
          Swaps two actors.
 boolean swapActor(int first, int second)
          Swaps two actors by index.
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getY, getZIndex, hasParent, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Group

public Group()
Method Detail

act

public void act(float delta)
Description copied from class: Actor
Updates the actor based on time. Typically this is called each frame by Stage.act(float).

The default implementation calls Action.act(float) on each action and removes actions that are complete.

Overrides:
act in class Actor
Parameters:
delta - Time in seconds since the last frame.

draw

public void draw(Batch batch,
                 float parentAlpha)
Draws the group and its children. The default implementation calls applyTransform(Batch, Matrix4) if needed, then drawChildren(Batch, float), then resetTransform(Batch) if needed.

Overrides:
draw in class Actor
parentAlpha - Should be multiplied with the actor's alpha, allowing a parent's alpha to affect all children.

setCullingArea

public void setCullingArea(Rectangle cullingArea)
Children completely outside of this rectangle will not be drawn. This is only valid for use with unrotated and unscaled actors!

Specified by:
setCullingArea in interface Cullable
Parameters:
cullingArea - The culling area in the child actor's coordinates.

hit

public Actor hit(float x,
                 float y,
                 boolean touchable)
Description copied from class: Actor
Returns the deepest actor that contains the specified point and is touchable and visible, or null if no actor was hit. The point is specified in the actor's local coordinate system (0,0 is the bottom left of the actor and width,height is the upper right).

This method is used to delegate touchDown, mouse, and enter/exit events. If this method returns null, those events will not occur on this Actor.

The default implementation returns this actor if the point is within this actor's bounds.

Overrides:
hit in class Actor
touchable - If true, the hit detection will respect the touchability.
See Also:
Touchable

addActor

public void addActor(Actor actor)
Adds an actor as a child of this group. The actor is first removed from its parent group, if any.

See Also:
Actor.remove()

addActorAt

public void addActorAt(int index,
                       Actor actor)
Adds an actor as a child of this group, at a specific index. The actor is first removed from its parent group, if any.

Parameters:
index - May be greater than the number of children.

addActorBefore

public void addActorBefore(Actor actorBefore,
                           Actor actor)
Adds an actor as a child of this group, immediately before another child actor. The actor is first removed from its parent group, if any.


addActorAfter

public void addActorAfter(Actor actorAfter,
                          Actor actor)
Adds an actor as a child of this group, immediately after another child actor. The actor is first removed from its parent group, if any.


removeActor

public boolean removeActor(Actor actor)
Removes an actor from this group. If the actor will not be used again and has actions, they should be cleared so the actions will be returned to their pool, if any. This is not done automatically.


clearChildren

public void clearChildren()
Removes all actors from this group.


clear

public void clear()
Removes all children, actions, and listeners from this group.

Overrides:
clear in class Actor

findActor

public Actor findActor(String name)
Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the group.


swapActor

public boolean swapActor(int first,
                         int second)
Swaps two actors by index. Returns false if the swap did not occur because the indexes were out of bounds.


swapActor

public boolean swapActor(Actor first,
                         Actor second)
Swaps two actors. Returns false if the swap did not occur because the actors are not children of this group.


getChildren

public SnapshotArray<Actor> getChildren()
Returns an ordered list of child actors in this group.


hasChildren

public boolean hasChildren()

setTransform

public void setTransform(boolean transform)
When true (the default), the Batch is transformed so children are drawn in their parent's coordinate system. This has a performance impact because Batch.flush() must be done before and after the transform. If the actors in a group are not rotated or scaled, then the transform for the group can be set to false. In this case, each child's position will be offset by the group's position for drawing, causing the children to appear in the correct location even though the Batch has not been transformed.


isTransform

public boolean isTransform()

localToDescendantCoordinates

public Vector2 localToDescendantCoordinates(Actor descendant,
                                            Vector2 localCoords)
Converts coordinates for this group to those of a descendant actor. The descendant does not need to be a direct child.

Throws:
IllegalArgumentException - if the specified actor is not a descendant of this group.

print

public void print()
Prints the actor hierarchy recursively for debugging purposes.



Copyright © 2014. All Rights Reserved.