Class 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 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.
      • drawChildren

        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.
      • 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 of computeTransform(). 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 before applyTransform(Batch, Matrix4). Note this causes the batch to be flushed.
      • resetTransform

        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.
      • 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:
        setCullingArea in interface Cullable
        Parameters:
        cullingArea - May be null.
      • hit

        @Null
        public Actor hit​(float x,
                         float y,
                         boolean touchable)
        Description copied from class: Actor
        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.

        Overrides:
        hit in class Actor
        touchable - If true, hit detection will respect the touchability.
        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. If actorAfter is not in this group, the actor is added as the last child.
      • removeActor

        public boolean removeActor​(Actor actor,
                                   boolean unfocus)
        Removes an actor from this group. Calls removeActorAt(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 be cleared so the actions will be returned to their pool, 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. Calls clearChildren(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.
        Overrides:
        clear in class Actor
      • 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: Actor
        Called by the framework when this actor or any ascendant is added to a group that is in the stage.
        Overrides:
        setStage in class Actor
        Parameters:
        stage - May be null if the actor or any ascendant is no longer in a 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 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 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.
      • toString

        public java.lang.String toString()
        Returns a description of the actor hierarchy, recursively.
        Overrides:
        toString in class Actor