libgdx API

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

A group is an Actor that contains other Actors (also other Groups which are Actors).

Author:
mzechner, Nathan Sweet

Field Summary
protected  Matrix4 batchTransform
           
protected  java.util.List<Actor> children
           
protected  Rectangle cullingArea
           
static boolean debug
           
static Texture debugTexture
           
protected  java.util.List<Group> groups
           
protected  java.util.List<Actor> immutableChildren
           
protected  java.util.List<Group> immutableGroups
           
 Actor lastTouchedChild
           
protected  Matrix3 localTransform
           
protected  ObjectMap<java.lang.String,Actor> namesToActors
           
protected  Matrix4 oldBatchTransform
           
protected  Vector2 point
           
 boolean transform
           
protected  Matrix3 worldTransform
           
 
Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor
actions, color, height, name, originX, originY, parent, rotation, scaleX, scaleY, stage, touchable, visible, width, x, y
 
Constructor Summary
Group()
           
Group(java.lang.String name)
          Creates a new Group with the given name.
 
Method Summary
 void act(float delta)
           
 void addActor(Actor actor)
          Adds an Actor to this Group.
 void addActorAfter(Actor actorAfter, Actor actor)
          Adds an Actor after the given Actor.
 void addActorAt(int index, Actor actor)
          Adds an Actor at the given index in the group.
 void addActorBefore(Actor actorBefore, Actor actor)
          Adds an Actor before the given Actor.
protected  void applyTransform(SpriteBatch batch)
           
protected  void childrenChanged()
          Called when actors are added to or removed from the group.
 void clear()
          Clears this Group, removing all contained Actors.
static void disableDebugging()
           
 void draw(SpriteBatch batch, float parentAlpha)
          Draws the Actor.
protected  void drawChild(Actor child, SpriteBatch batch, float parentAlpha)
           
protected  void drawChildren(SpriteBatch batch, float parentAlpha)
           
static void enableDebugging(java.lang.String debugTextureFile)
           
 Actor findActor(java.lang.String name)
          Finds the Actor with the given name in this Group and its children.
 java.util.List<Actor> getActors()
           
 java.util.List<Group> getGroups()
           
 Actor hit(float x, float y)
           
 boolean isDescendant(Actor actor)
           
 void removeActor(Actor actor)
          Removes an Actor from this Group.
 void removeActorRecursive(Actor actor)
          Removes an Actor from this Group recursively by checking if the Actor is in this group or one of its child-groups.
protected  void resetTransform(SpriteBatch batch)
           
 void setCullingArea(Rectangle cullingArea)
           
 void sortChildren(java.util.Comparator<Actor> comparator)
          Sorts the children via the given Comparator.
 boolean swapActor(Actor first, Actor second)
          Swap two actors' sort order by reference.
 boolean swapActor(int first, int second)
          Swap two actors' sort order by index.
static void toChildCoordinates(Actor child, float x, float y, Vector2 out)
          Transforms the coordinates given in the child's parent coordinate system to the child Actor's coordinate system.
 void toLocalCoordinates(Actor descendant, Vector2 point)
          Converts coordinates for this group to those of a descendant actor.
 boolean touchDown(float x, float y, int pointer)
           
 boolean touchMoved(float x, float y)
           
protected  Matrix4 updateTransform()
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
action, clearActions, getStage, isMarkedToRemove, keyDown, keyTyped, keyUp, markToRemove, remove, scrolled, toLocalCoordinates, toString, touchDragged, touchUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debugTexture

public static Texture debugTexture

debug

public static boolean debug

children

protected final java.util.List<Actor> children

immutableChildren

protected final java.util.List<Actor> immutableChildren

groups

protected final java.util.List<Group> groups

immutableGroups

protected final java.util.List<Group> immutableGroups

namesToActors

protected final ObjectMap<java.lang.String,Actor> namesToActors

localTransform

protected final Matrix3 localTransform

worldTransform

protected final Matrix3 worldTransform

batchTransform

protected final Matrix4 batchTransform

oldBatchTransform

protected final Matrix4 oldBatchTransform

transform

public boolean transform

lastTouchedChild

public Actor lastTouchedChild

cullingArea

protected Rectangle cullingArea

point

protected final Vector2 point
Constructor Detail

Group

public Group()

Group

public Group(java.lang.String name)
Creates a new Group with the given name.

Parameters:
name - the name of the group
Method Detail

act

public void act(float delta)
Overrides:
act in class Actor

draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Actor
Draws the Actor. The spriteBatch is configured so that the Actor can draw in its parents coordinate system. The parent's alpha is passed to the method in order for the Actor to multiply it with its own alpha. This will allow FadeIn and other Actions to have an effect even if they are only set on the parent of the Actor.

Specified by:
draw in class Actor
Parameters:
batch - the spritebatch to render with
parentAlpha - the parent's alpha value.

drawChildren

protected void drawChildren(SpriteBatch batch,
                            float parentAlpha)

drawChild

protected void drawChild(Actor child,
                         SpriteBatch batch,
                         float parentAlpha)

applyTransform

protected void applyTransform(SpriteBatch batch)

updateTransform

protected Matrix4 updateTransform()

resetTransform

protected void resetTransform(SpriteBatch batch)

setCullingArea

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

touchDown

public boolean touchDown(float x,
                         float y,
                         int pointer)
Overrides:
touchDown in class Actor

touchMoved

public boolean touchMoved(float x,
                          float y)
Overrides:
touchMoved in class Actor

hit

public Actor hit(float x,
                 float y)
Specified by:
hit in class Actor

childrenChanged

protected void childrenChanged()
Called when actors are added to or removed from the group.


addActor

public void addActor(Actor actor)
Adds an Actor to this Group. The order Actors are added is reversed for hit testing.

Parameters:
actor - the Actor

addActorAt

public void addActorAt(int index,
                       Actor actor)
Adds an Actor at the given index in the group. The first Actor added will be at index 0 and so on. Throws an IndexOutOfBoundsException in case the index is invalid.

Parameters:
index - the index to add the actor at.

addActorBefore

public void addActorBefore(Actor actorBefore,
                           Actor actor)
Adds an Actor before the given Actor.

Parameters:
actorBefore - the Actor to add the other actor in front of
actor - the Actor to add

addActorAfter

public void addActorAfter(Actor actorAfter,
                          Actor actor)
Adds an Actor after the given Actor.

Parameters:
actorAfter - the Actor to add the other Actor behind
actor - the Actor to add

removeActor

public void removeActor(Actor actor)
Removes an Actor from this Group.

Parameters:
actor -

removeActorRecursive

public void removeActorRecursive(Actor actor)
Removes an Actor from this Group recursively by checking if the Actor is in this group or one of its child-groups.

Parameters:
actor - the Actor

findActor

public Actor findActor(java.lang.String name)
Finds the Actor with the given name in this Group and its children.

Parameters:
name - the name of the Actor
Returns:
the Actor or null

swapActor

public boolean swapActor(int first,
                         int second)
Swap two actors' sort order by index. 0 is lowest while getActors().size() - 1 is largest.

Parameters:
first - first Actor index
second - second Actor index
Returns:
false if indices are out of bound.

swapActor

public boolean swapActor(Actor first,
                         Actor second)
Swap two actors' sort order by reference.

Parameters:
first - first Actor
second - second Actor
Returns:
false if any of the Actors is not the child of this Group.

getActors

public java.util.List<Actor> getActors()
Returns:
all child Actors as an ordered list.

getGroups

public java.util.List<Group> getGroups()
Returns:
all child Groups as an unordered list.

clear

public void clear()
Clears this Group, removing all contained Actors.


sortChildren

public void sortChildren(java.util.Comparator<Actor> comparator)
Sorts the children via the given Comparator.

Parameters:
comparator - the comparator.

toLocalCoordinates

public void toLocalCoordinates(Actor descendant,
                               Vector2 point)
Converts coordinates for this group to those of a descendant actor.

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

isDescendant

public boolean isDescendant(Actor actor)

toChildCoordinates

public static void toChildCoordinates(Actor child,
                                      float x,
                                      float y,
                                      Vector2 out)
Transforms the coordinates given in the child's parent coordinate system to the child Actor's coordinate system.

Parameters:
child - the child Actor
x - the x-coordinate in the Group's coordinate system
y - the y-coordinate in the Group's coordinate system
out - the output Vector2

enableDebugging

public static void enableDebugging(java.lang.String debugTextureFile)

disableDebugging

public static void disableDebugging()

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)