Package arc.scene

Class Group

All Implemented Interfaces:
Cullable
Direct Known Subclasses:
ResearchDialog.View, WidgetGroup

public abstract class Group extends Element 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.

  • Field Details

    • children

      protected final SnapshotSeq<Element> children
    • transform

      protected boolean transform
    • cullingArea

      protected Rect cullingArea
  • Constructor Details

    • Group

      public Group()
  • Method Details

    • act

      public void act(float delta)
      Description copied from class: Element
      Updates the actor based on time. Typically this is called each frame by Scene.act(float).

      The default implementation calls Action.act(float) on each action and removes actions that are complete.

      Overrides:
      act in class Element
      Parameters:
      delta - Time in seconds since the last frame.
    • draw

      public void draw()
      Description copied from class: Element
      Draws the element. Does nothing by default.
      Overrides:
      draw in class Element
    • drawChildren

      protected void drawChildren()
    • computeTransform

      protected Mat computeTransform()
      Returns the transform for this group's coordinate system.
    • applyTransform

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

      protected void resetTransform()
      Restores the batch transform to what it was before applyTransform(Mat). Note this causes the batch to be flushed.
    • getCullingArea

      public Rect getCullingArea()
      Returns:
      May be null.
      See Also:
    • setCullingArea

      public void setCullingArea(Rect 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

      public Element hit(float x, float y, boolean touchable)
      Description copied from class: Element
      Returns the deepest actor that contains the specified point and is 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.

      Overrides:
      hit in class Element
      touchable - If true, the hit detection will respect the touchability.
      See Also:
    • childrenChanged

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

      public void forEach(Cons<Element> cons)
      Recursively iterates through every child of this group.
    • fill

      public Element fill(Table.DrawRect rect)
    • fill

      public void fill(Cons<Table> cons)
      Adds and returns a table. This table will fill the whole scene.
    • fill

      public void fill(Drawable background, Cons<Table> cons)
      Adds and returns a table. This table will fill the whole scene.
    • addChild

      public void addChild(Element 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.
    • addChildAt

      public void addChildAt(int index, Element 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.
    • addChildBefore

      public void addChildBefore(Element actorBefore, Element 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.
    • addChildAfter

      public void addChildAfter(Element actorAfter, Element 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.
    • removeChild

      public boolean removeChild(Element actor)
      Removes an actor from this group and unfocuses it. Calls removeChild(Element, boolean) with true.
    • removeChild

      public boolean removeChild(Element actor, 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, Scene.unfocus(Element) is called.
      Returns:
      true if the actor was removed from this group.
    • clearChildren

      public void clearChildren()
      Removes all actors from this group.
    • clear

      public void clear()
      Removes all children, actions, and listeners from this group.
      Overrides:
      clear in class Element
    • find

      public <T extends Element> T find(String name)
      Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the group.
    • findVisible

      public <T extends Element> T findVisible(String name)
      Finds only visible elements.
    • find

      public <T extends Element> T find(Boolf<Element> pred)
      Find element by a predicate.
    • setScene

      protected void setScene(Scene stage)
      Description copied from class: Element
      Called by the framework when this actor or any parent is added to a group that is in the stage.
      Overrides:
      setScene in class Element
      Parameters:
      stage - May be null if the actor or any parent 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(Element first, Element second)
      Swaps two actors. Returns false if the swap did not occur because the actors are not children of this group.
    • getChildren

      public SnapshotSeq<Element> getChildren()
      Returns an ordered list of child actors in this group.
    • hasChildren

      public boolean hasChildren()
    • isTransform

      public boolean isTransform()
    • 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.
    • localToDescendantCoordinates

      public Vec2 localToDescendantCoordinates(Element descendant, Vec2 localCoords)
      Converts coordinates for this group to those of a descendant actor. The descendant does not need to be a direct child.
    • toString

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