Package com.badlogic.gdx.scenes.scene2d
Class Group
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.Actor
-
- 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.
-
-
Constructor Summary
Constructors Constructor Description Group()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidact(float delta)Updates the actor based on time.voidaddActor(Actor actor)Adds an actor as a child of this group, removing it from its previous parent.voidaddActorAfter(Actor actorAfter, Actor actor)Adds an actor as a child of this group immediately after another child actor, removing it from its previous parent.voidaddActorAt(int index, Actor actor)Adds an actor as a child of this group at a specific index, removing it from its previous parent.voidaddActorBefore(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 voidapplyTransform(Batch batch, Matrix4 transform)Set the batch's transformation matrix, often with the result ofcomputeTransform().protected voidapplyTransform(ShapeRenderer shapes, Matrix4 transform)Set the shape renderer transformation matrix, often with the result ofcomputeTransform().protected voidchildrenChanged()Called when actors are added to or removed from the group.voidclear()Removes all children, actions, and listeners from this group.voidclear(boolean unfocus)Removes all children, actions, and listeners from this group.voidclearChildren()Removes all actors from this group and unfocuses them.voidclearChildren(boolean unfocus)Removes all actors from this group.protected Matrix4computeTransform()Returns the transform for this group's coordinate system.GroupdebugAll()CallssetDebug(boolean, boolean)withtrue, true.voiddraw(Batch batch, float parentAlpha)Draws the group and its children.protected voiddrawChildren(Batch batch, float parentAlpha)Draws all children.voiddrawDebug(ShapeRenderer shapes)Draws this actor's debug lines ifActor.getDebug()is true and, regardless ofActor.getDebug(), callsActor.drawDebug(ShapeRenderer)on each child.protected voiddrawDebugChildren(ShapeRenderer shapes)Draws all children.<T extends Actor>
TfindActor(java.lang.String name)Returns the first actor found with the specified name.ActorgetChild(int index)Returns the child at the specified index.SnapshotArray<Actor>getChildren()Returns an ordered list of child actors in this group.RectanglegetCullingArea()booleanhasChildren()Actorhit(float x, float y, boolean touchable)booleanisTransform()Vector2localToDescendantCoordinates(Actor descendant, Vector2 localCoords)Converts coordinates for this group to those of a descendant actor.booleanremoveActor(Actor actor)Removes an actor from this group and unfocuses it.booleanremoveActor(Actor actor, boolean unfocus)Removes an actor from this group.ActorremoveActorAt(int index, boolean unfocus)Removes an actor from this group.protected voidresetTransform(Batch batch)Restores the batch transform to what it was beforeapplyTransform(Batch, Matrix4).protected voidresetTransform(ShapeRenderer shapes)Restores the shape renderer transform to what it was beforeapplyTransform(Batch, Matrix4).voidsetCullingArea(Rectangle cullingArea)Children completely outside of this rectangle will not be drawn.voidsetDebug(boolean enabled, boolean recursively)If true,drawDebug(ShapeRenderer)will be called for this group and, optionally, all children recursively.protected voidsetStage(Stage stage)Called by the framework when this actor or any ascendant is added to a group that is in the stage.voidsetTransform(boolean transform)When true (the default), the Batch is transformed so children are drawn in their parent's coordinate system.booleanswapActor(int first, int second)Swaps two actors by index.booleanswapActor(Actor first, Actor second)Swaps two actors.java.lang.StringtoString()Returns a description of the actor hierarchy, recursively.-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, toBack, toFront
-
-
-
-
Method Detail
-
act
public void act(float delta)
Description copied from class:ActorUpdates the actor based on time. Typically this is called each frame byStage.act(float).The default implementation calls
Action.act(float)on each action and removes actions that are complete.
-
draw
public void draw(Batch batch, float parentAlpha)
Draws the group and its children. The default implementation callsapplyTransform(Batch, Matrix4)if needed, thendrawChildren(Batch, float), thenresetTransform(Batch)if needed.
-
drawChildren
protected void drawChildren(Batch batch, float parentAlpha)
Draws all children.applyTransform(Batch, Matrix4)should be called before andresetTransform(Batch)after this method iftransformis true. Iftransformis 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 theculling area, if set.
-
drawDebug
public void drawDebug(ShapeRenderer shapes)
Draws this actor's debug lines ifActor.getDebug()is true and, regardless ofActor.getDebug(), callsActor.drawDebug(ShapeRenderer)on each child.
-
drawDebugChildren
protected void drawDebugChildren(ShapeRenderer shapes)
Draws all children.applyTransform(Batch, Matrix4)should be called before andresetTransform(Batch)after this method iftransformis true. Iftransformis 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 theculling area, if set.
-
computeTransform
protected Matrix4 computeTransform()
Returns the transform for this group's coordinate system.
-
applyTransform
protected void applyTransform(Batch batch, Matrix4 transform)
Set the batch's transformation matrix, often with the result ofcomputeTransform(). Note this causes the batch to be flushed.resetTransform(Batch)will restore the transform to what it was before this call.
-
resetTransform
protected void resetTransform(Batch batch)
Restores the batch transform to what it was beforeapplyTransform(Batch, Matrix4). Note this causes the batch to be flushed.
-
applyTransform
protected void applyTransform(ShapeRenderer shapes, Matrix4 transform)
Set the shape renderer transformation matrix, often with the result ofcomputeTransform(). Note this causes the shape renderer to be flushed.resetTransform(ShapeRenderer)will restore the transform to what it was before this call.
-
resetTransform
protected void resetTransform(ShapeRenderer shapes)
Restores the shape renderer transform to what it was beforeapplyTransform(Batch, Matrix4). Note this causes the shape renderer to be flushed.
-
setCullingArea
public void setCullingArea(@Null 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:
setCullingAreain interfaceCullable- Parameters:
cullingArea- May be null.
-
getCullingArea
@Null public Rectangle getCullingArea()
- Returns:
- May be null.
- See Also:
setCullingArea(Rectangle)
-
hit
@Null public Actor hit(float x, float y, boolean touchable)
Description copied from class:ActorReturns the deepestvisible(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.
- Overrides:
hitin classActortouchable- If true, hit detection will respect thetouchability.- See Also:
Touchable
-
childrenChanged
protected void childrenChanged()
Called when actors are added to or removed from the group.
-
addActor
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.
-
addActorAt
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- 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, removing it from its previous parent. If the actor is already a child of this group, no changes are made.
-
addActorAfter
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. IfactorAfteris not in this group, the actor is added as the last child.
-
removeActor
public boolean removeActor(Actor actor)
Removes an actor from this group and unfocuses it. CallsremoveActor(Actor, boolean)with true.
-
removeActor
public boolean removeActor(Actor actor, boolean unfocus)
Removes an actor from this group. CallsremoveActorAt(int, boolean)with the actor's child index.
-
removeActorAt
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 beclearedso the actions will be returned to theirpool, if any. This is not done automatically.- Parameters:
unfocus- If true,Stage.unfocus(Actor)is called.- Returns:
- the actor removed from this group.
-
clearChildren
public void clearChildren()
Removes all actors from this group and unfocuses them. CallsclearChildren(boolean)with true.
-
clearChildren
public void clearChildren(boolean unfocus)
Removes all actors from this group.
-
clear
public void clear()
Removes all children, actions, and listeners from this group. The children are unfocused.
-
clear
public void clear(boolean unfocus)
Removes all children, actions, and listeners from this group.
-
findActor
@Null public <T extends Actor> T findActor(java.lang.String name)
Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the group.
-
setStage
protected void setStage(Stage stage)
Description copied from class:ActorCalled by the framework when this actor or any ascendant is added to a group that is in the stage.
-
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.
-
getChild
public Actor getChild(int index)
Returns the child at the specified index.
-
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 becauseBatch.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 an immediate child.- Throws:
java.lang.IllegalArgumentException- if the specified actor is not a descendant of this group.
-
setDebug
public void setDebug(boolean enabled, boolean recursively)If true,drawDebug(ShapeRenderer)will be called for this group and, optionally, all children recursively.
-
debugAll
public Group debugAll()
CallssetDebug(boolean, boolean)withtrue, true.
-
-