APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d

public Class Group

extends Actor
implements Cullable
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.utils.Cullable
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
Imports
com.badlogic.gdx.graphics.g2d.Batch, com.badlogic.gdx.graphics.glutils.ShapeRenderer, com.badlogic.gdx.math.Affine2, .Matrix4, .Rectangle, .Vector2, com.badlogic.gdx.scenes.scene2d.utils.Cullable, com.badlogic.gdx.utils.Array, .Null, .SnapshotArray

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.

Authors
mzechner, Nathan Sweet

Field Summary

Modifier and TypeField and Description
pack-priv final SnapshotArray<Actor>
private final Matrix4
private Rectangle
private final Matrix4
private static final Vector2
pack-priv boolean
private final Affine2
Inherited from com.badlogic.gdx.scenes.scene2d.Actor:
colorheightoriginXoriginYparentPOOLSrotationscaleXscaleYwidthxy

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
act(float delta)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.act.

Updates the actor based on time.

public void
addActor(Actor actor)

Adds an actor as a child of this group, removing it from its previous parent.

public void
addActorAfter(Actor actorAfter, Actor actor)

Adds an actor as a child of this group immediately after another child actor, removing it from its previous parent.

public void
addActorAt(int
May be greater than the number of children.
index
,
Actor actor)

Adds an actor as a child of this group at a specific index, removing it from its previous parent.

public void
addActorBefore(Actor actorBefore, Actor actor)

Adds an actor as a child of this group immediately before another child actor, removing it from its previous parent.

protected void
applyTransform(Batch batch, Matrix4 transform)

Set the batch's transformation matrix, often with the result of computeTransform().

protected void
applyTransform(ShapeRenderer shapes, Matrix4 transform)

Set the shape renderer transformation matrix, often with the result of computeTransform().

protected void
childrenChanged()

Called when actors are added to or removed from the group.

public void
clear()

Overrides com.badlogic.gdx.scenes.scene2d.Actor.clear.

Removes all children, actions, and listeners from this group.

public void
clear(boolean unfocus)

Removes all children, actions, and listeners from this group.

public void
clearChildren()

Removes all actors from this group and unfocuses them.

public void
clearChildren(boolean unfocus)

Removes all actors from this group.

protected Matrix4
computeTransform()

Returns the transform for this group's coordinate system.

public Group
debugAll()

Calls setDebug(boolean, boolean) with true, true.

public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.draw.

Draws the group and its children.

protected void
drawChildren(Batch batch, float parentAlpha)

Draws all children.

public void
drawDebug(ShapeRenderer shapes)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.drawDebug.

Draws this actor's debug lines if getDebug() is true and, regardless of getDebug(), calls Actor#drawDebug(ShapeRenderer) on each child.

protected void
drawDebugChildren(ShapeRenderer shapes)

Draws all children.

public <T extends Actor> T
findActor(String name)

Returns the first actor found with the specified name.

public Actor
getChild(int index)

Returns the child at the specified index.

public SnapshotArray<Actor>
getChildren()

Returns an ordered list of child actors in this group.

public Rectangle
getCullingArea()

Returns: May be null.

public boolean
public Actor
hit(float x, float y, boolean touchable)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.hit.

Returns the deepest visible (and optionally, touchable) actor that contains the specified point, or null if no actor was hit.

public boolean
public Vector2
localToDescendantCoordinates(Actor descendant, Vector2 localCoords)

Converts coordinates for this group to those of a descendant actor.

public boolean
removeActor(Actor actor)

Removes an actor from this group and unfocuses it.

public boolean
removeActor(Actor actor, boolean unfocus)

Removes an actor from this group.

public Actor

Returns:

the actor removed from this group.
removeActorAt
(int index, boolean
If true, Stage#unfocus(Actor) is called.
unfocus
)

Removes an actor from this group.

protected void
resetTransform(Batch batch)

Restores the batch transform to what it was before applyTransform(Batch, Matrix4).

protected void
resetTransform(ShapeRenderer shapes)

Restores the shape renderer transform to what it was before applyTransform(Batch, Matrix4).

public void
setCullingArea(Rectangle
May be null.
cullingArea
)

Implements com.badlogic.gdx.scenes.scene2d.utils.Cullable.setCullingArea.

Children completely outside of this rectangle will not be drawn.

public void
setDebug(boolean enabled, boolean recursively)

If true, drawDebug(ShapeRenderer) will be called for this group and, optionally, all children recursively.

protected void
setStage(Stage stage)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.setStage.

Called by the framework when this actor or any ascendant is added to a group that is in the stage.

public void
setTransform(boolean transform)

When true (the default), the Batch is transformed so children are drawn in their parent's coordinate system.

public boolean
swapActor(int first, int second)

Swaps two actors by index.

public boolean
swapActor(Actor first, Actor second)

Swaps two actors.

public String
toString()

Overrides com.badlogic.gdx.scenes.scene2d.Actor.toString.

Returns a description of the actor hierarchy, recursively.

pack-priv void
toString(StringBuilder buffer, int indent)

Inherited from com.badlogic.gdx.scenes.scene2d.Actor:
addActionaddCaptureListeneraddListenerancestorsVisibleascendantsVisibleclearActionsclearListenersclipBeginclipBeginclipEnddebugdrawDebugBoundsfirefirstAscendantgetActionsgetCaptureListenersgetColorgetDebuggetHeightgetListenersgetNamegetOriginXgetOriginYgetParentgetRightgetRotationgetScaleXgetScaleYgetStagegetTopgetTouchablegetUserObjectgetWidthgetXgetXgetYgetYgetZIndexhasActionshasKeyboardFocushasParenthasScrollFocusisAscendantOfisDescendantOfisTouchableisTouchFocusListenerisTouchFocusTargetisVisiblelocalToActorCoordinateslocalToAscendantCoordinateslocalToParentCoordinateslocalToScreenCoordinateslocalToStageCoordinatesmoveBynotifyparentToLocalCoordinatespositionChangedremoveremoveActionremoveCaptureListenerremoveListenerrotateByrotationChangedscaleByscaleByscaleChangedscreenToLocalCoordinatessetBoundssetColorsetColorsetDebugsetHeightsetNamesetOriginsetOriginsetOriginXsetOriginYsetParentsetPositionsetPositionsetRotationsetScalesetScalesetScaleXsetScaleYsetSizesetTouchablesetUserObjectsetVisiblesetWidthsetXsetXsetYsetYsetZIndexsizeBysizeBysizeChangedstageToLocalCoordinatestoBacktoFront

Field Detail

childrenback to summary
pack-priv final SnapshotArray<Actor> children
computedTransformback to summary
private final Matrix4 computedTransform
cullingAreaback to summary
private Rectangle cullingArea
Annotations
@Null
oldTransformback to summary
private final Matrix4 oldTransform
tmpback to summary
private static final Vector2 tmp
transformback to summary
pack-priv boolean transform
worldTransformback to summary
private final Affine2 worldTransform

Constructor Detail

Groupback to summary
public Group()

Method Detail

actback to summary
public void act(float delta)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.act.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.act.

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.

addActorback to summary
public void addActor(Actor actor)

Adds an actor as a child of this group, removing it from its previous parent. If the actor is already a child of this group, no changes are made.

addActorAfterback to summary
public void addActorAfter(Actor actorAfter, Actor actor)

Adds an actor as a child of this group immediately after another child actor, removing it from its previous parent. If the actor is already a child of this group, no changes are made. If actorAfter is not in this group, the actor is added as the last child.

addActorAtback to summary
public void addActorAt(int index, Actor actor)

Adds an actor as a child of this group at a specific index, removing it from its previous parent. If the actor is already a child of this group, no changes are made.

Parameters
index:int

May be greater than the number of children.

addActorBeforeback to summary
public void addActorBefore(Actor actorBefore, Actor actor)

Adds an actor as a child of this group immediately before another child actor, removing it from its previous parent. If the actor is already a child of this group, no changes are made.

applyTransformback to summary
protected void applyTransform(Batch batch, Matrix4 transform)

Set the batch's transformation matrix, often with the result of computeTransform(). Note this causes the batch to be flushed. resetTransform(Batch) will restore the transform to what it was before this call.

applyTransformback to summary
protected void applyTransform(ShapeRenderer shapes, Matrix4 transform)

Set the shape renderer transformation matrix, often with the result of computeTransform(). Note this causes the shape renderer to be flushed. resetTransform(ShapeRenderer) will restore the transform to what it was before this call.

childrenChangedback to summary
protected void childrenChanged()

Called when actors are added to or removed from the group.

clearback to summary
public void clear()

Overrides com.badlogic.gdx.scenes.scene2d.Actor.clear.

Removes all children, actions, and listeners from this group. The children are unfocused.

clearback to summary
public void clear(boolean unfocus)

Removes all children, actions, and listeners from this group.

clearChildrenback to summary
public void clearChildren()

Removes all actors from this group and unfocuses them. Calls clearChildren(boolean) with true.

clearChildrenback to summary
public void clearChildren(boolean unfocus)

Removes all actors from this group.

computeTransformback to summary
protected Matrix4 computeTransform()

Returns the transform for this group's coordinate system.

debugAllback to summary
public Group debugAll()

Calls setDebug(boolean, boolean) with true, true.

drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.draw.

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

drawChildrenback to summary
protected void drawChildren(Batch batch, float parentAlpha)

Draws all children. applyTransform(Batch, Matrix4) should be called before and resetTransform(Batch) after this method if transform is true. If transform is false these methods don't need to be called, children positions are temporarily offset by the group position when drawn. This method avoids drawing children completely outside the culling area, if set.

drawDebugback to summary
public void drawDebug(ShapeRenderer shapes)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.drawDebug.

Draws this actor's debug lines if getDebug() is true and, regardless of getDebug(), calls Actor#drawDebug(ShapeRenderer) on each child.

drawDebugChildrenback to summary
protected void drawDebugChildren(ShapeRenderer shapes)

Draws all children. applyTransform(Batch, Matrix4) should be called before and resetTransform(Batch) after this method if transform is true. If transform is false these methods don't need to be called, children positions are temporarily offset by the group position when drawn. This method avoids drawing children completely outside the culling area, if set.

findActorback to summary
public <T extends Actor> T findActor(String name)

Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the group.

Annotations
@Null
getChildback to summary
public Actor getChild(int index)

Returns the child at the specified index.

getChildrenback to summary
public SnapshotArray<Actor> getChildren()

Returns an ordered list of child actors in this group.

getCullingAreaback to summary
public Rectangle getCullingArea()
Returns:Rectangle

May be null.

Annotations
@Null
See Also
setCullingArea(Rectangle)
hasChildrenback to summary
public boolean hasChildren()
hitback to summary
public Actor hit(float x, float y, boolean touchable)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.hit.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.hit.

Returns the deepest visible (and optionally, touchable) actor that contains the specified point, 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 and this actor is visible.

Annotations
@Null
isTransformback to summary
public boolean isTransform()
localToDescendantCoordinatesback to summary
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 an immediate child.

Exceptions
IllegalArgumentException:
if the specified actor is not a descendant of this group.
removeActorback to summary
public boolean removeActor(Actor actor)

Removes an actor from this group and unfocuses it. Calls removeActor(Actor, boolean) with true.

removeActorback to summary
public boolean removeActor(Actor actor, boolean unfocus)

Removes an actor from this group. Calls removeActorAt(int, boolean) with the actor's child index.

removeActorAtback to summary
public Actor removeActorAt(int index, boolean unfocus)

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.

Parameters
unfocus:boolean

If true, Stage#unfocus(Actor) is called.

Returns:Actor

the actor removed from this group.

resetTransformback to summary
protected void resetTransform(Batch batch)

Restores the batch transform to what it was before applyTransform(Batch, Matrix4). Note this causes the batch to be flushed.

resetTransformback to summary
protected void resetTransform(ShapeRenderer shapes)

Restores the shape renderer transform to what it was before applyTransform(Batch, Matrix4). Note this causes the shape renderer to be flushed.

setCullingAreaback to summary
public void setCullingArea(Rectangle cullingArea)

Implements com.badlogic.gdx.scenes.scene2d.utils.Cullable.setCullingArea.

Children completely outside of this rectangle will not be drawn. This is only valid for use with unrotated and unscaled actors.

Parameters
cullingArea:Rectangle

May be null.

setDebugback to summary
public void setDebug(boolean enabled, boolean recursively)

If true, drawDebug(ShapeRenderer) will be called for this group and, optionally, all children recursively.

setStageback to summary
protected void setStage(Stage stage)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.setStage.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.setStage.

Called by the framework when this actor or any ascendant is added to a group that is in the stage.

setTransformback to summary
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.

swapActorback to summary
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.

swapActorback to summary
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.

toStringback to summary
public String toString()

Overrides com.badlogic.gdx.scenes.scene2d.Actor.toString.

Returns a description of the actor hierarchy, recursively.

toStringback to summary
pack-priv void toString(StringBuilder buffer, int indent)