public class Group extends Actor implements Cullable
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 and Description |
---|
Group() |
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
void |
clear()
Removes all children, actions, and listeners from this group.
|
void |
clearChildren()
Removes all actors from this group.
|
protected Matrix4 |
computeTransform()
Returns the transform for this group's coordinate system.
|
Group |
debugAll()
Calls
setDebug(boolean, boolean) with true, true . |
void |
draw(Batch batch,
float parentAlpha)
Draws the group and its children.
|
protected void |
drawChildren(Batch batch,
float parentAlpha)
Draws all children.
|
void |
drawDebug(ShapeRenderer shapes)
Draws this actor's debug lines if
Actor.getDebug() is true and, regardless of Actor.getDebug() , calls
Actor.drawDebug(ShapeRenderer) on each child. |
protected void |
drawDebugChildren(ShapeRenderer shapes)
Draws all children.
|
<T extends Actor> |
findActor(java.lang.String name)
Returns the first actor found with the specified name.
|
SnapshotArray<Actor> |
getChildren()
Returns an ordered list of child actors in this group.
|
Rectangle |
getCullingArea() |
boolean |
hasChildren() |
Actor |
hit(float x,
float y,
boolean touchable)
|
boolean |
isTransform() |
Vector2 |
localToDescendantCoordinates(Actor descendant,
Vector2 localCoords)
Converts coordinates for this group to those of a descendant actor.
|
boolean |
removeActor(Actor actor)
Calls
removeActor(Actor, boolean) with true. |
boolean |
removeActor(Actor actor,
boolean 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) . |
void |
setCullingArea(Rectangle cullingArea)
Children completely outside of this rectangle will not be drawn.
|
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)
Called by the framework when this actor or any parent is added to a group that is in the stage.
|
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.
|
java.lang.String |
toString()
Returns a description of the actor hierarchy, recursively.
|
addAction, addCaptureListener, addListener, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebugBounds, fire, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasParent, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, scaleBy, scaleBy, 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, setY, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, toBack, toFront
public void act(float delta)
Actor
Stage.act(float)
.
The default implementation calls Action.act(float)
on each action and removes actions that are complete.
public void draw(Batch batch, float parentAlpha)
applyTransform(Batch, Matrix4)
if needed, then
drawChildren(Batch, float)
, then resetTransform(Batch)
if needed.protected void drawChildren(Batch batch, float parentAlpha)
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.public void drawDebug(ShapeRenderer shapes)
Actor.getDebug()
is true and, regardless of Actor.getDebug()
, calls
Actor.drawDebug(ShapeRenderer)
on each child.protected void drawDebugChildren(ShapeRenderer shapes)
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.protected Matrix4 computeTransform()
protected void applyTransform(Batch batch, Matrix4 transform)
computeTransform()
. Note this causes the batch to
be flushed. resetTransform(Batch)
will restore the transform to what it was before this call.protected void resetTransform(Batch batch)
applyTransform(Batch, Matrix4)
. Note this causes the batch to be
flushed.protected void applyTransform(ShapeRenderer shapes, Matrix4 transform)
computeTransform()
. Note this causes the
shape renderer to be flushed. resetTransform(ShapeRenderer)
will restore the transform to what it was before this
call.protected void resetTransform(ShapeRenderer shapes)
applyTransform(Batch, Matrix4)
. Note this causes the
shape renderer to be flushed.public void setCullingArea(Rectangle cullingArea)
setCullingArea
in interface Cullable
cullingArea
- The culling area in the child actor's coordinates.public Rectangle getCullingArea()
setCullingArea(Rectangle)
public Actor hit(float x, float y, boolean touchable)
Actor
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.
hit
in class Actor
touchable
- If true, the hit detection will respect the touchability
.Touchable
protected void childrenChanged()
public void addActor(Actor actor)
public void addActorAt(int index, Actor actor)
index
- May be greater than the number of children.public void addActorBefore(Actor actorBefore, Actor actor)
public void addActorAfter(Actor actorAfter, Actor actor)
public boolean removeActor(Actor actor)
removeActor(Actor, boolean)
with true.public boolean removeActor(Actor actor, boolean unfocus)
cleared
so the actions will be returned to their
pool
, if any. This is not done automatically.unfocus
- If true, Stage.unfocus(Actor)
is called.public void clearChildren()
public void clear()
public <T extends Actor> T findActor(java.lang.String name)
protected void setStage(Stage stage)
Actor
public boolean swapActor(int first, int second)
public boolean swapActor(Actor first, Actor second)
public SnapshotArray<Actor> getChildren()
public boolean hasChildren()
public void setTransform(boolean transform)
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.public boolean isTransform()
public Vector2 localToDescendantCoordinates(Actor descendant, Vector2 localCoords)
java.lang.IllegalArgumentException
- if the specified actor is not a descendant of this group.public void setDebug(boolean enabled, boolean recursively)
drawDebug(ShapeRenderer)
will be called for this group and, optionally, all children recursively.public Group debugAll()
setDebug(boolean, boolean)
with true, true
.