Class Container

java.lang.Object
nl.colorize.multimedialib.stage.Container
All Implemented Interfaces:
Updatable, Graphic2D

public class Container extends Object implements Graphic2D
Display object that acts as a container for holding 2D graphics. Children are visited in the order they were added, which means children further down the list will be drawn "on top of" children earlier in the list.

Containers have their own Transform, and this is inherited by their children. In other words, the child display object's position is relative to its parent container's position, not relative to the stage.

Containers keep track of added and removed children. This information can be retrieved in two ways: by registering observers that are notified whenever a child is added or removed, or via a queue that can be polled on a frame-by-frame basis.

Containers can optionally be given a name. This name should be used purely for information purposes. Trying to look up containers by name during each frame will be too slow for most applications.

  • Constructor Details

    • Container

      public Container(String name)
    • Container

      public Container()
  • Method Details

    • addChild

      public void addChild(Graphic2D child)
    • addChild

      public void addChild(Graphic2D child, Point2D relativePosition)
      Convenience method that adds the specified graphics to this container, then moved the graphics' position to the specified offset.
    • addChild

      public void addChild(Graphic2D child, float relativeX, float relativeY)
      Convenience method that adds the specified graphics to this container, then moved the graphics' position to the specified offset.
    • addChildContainer

      public Container addChildContainer()
      Convenience method that creates a child container, adds it as a child to this container, then returns the created child container.
    • removeChild

      public void removeChild(Graphic2D child)
    • clearChildren

      public void clearChildren()
    • getChildren

      public Iterable<Graphic2D> getChildren()
    • forEach

      @Deprecated public <T extends Graphic2D> void forEach(Class<T> type, Consumer<T> callback)
      Deprecated.
      This method requires the container to iterate over all of its children, which has a performance impact if the container is large and this is done every frame. Prefer direct references to the relevant graphics over using this method.
      Invokes the specified callback function for all matching graphics within this container.
    • update

      public void update(float deltaTime)
      Description copied from interface: Updatable
      Updates this object for the current frame. deltaTime indicates the elapsed time since the last frame update, in seconds.
      Specified by:
      update in interface Updatable
    • getStageBounds

      public Rect getStageBounds()
      Returns the smallest rectangle that can contain the bounds of all graphics within this container.
      Specified by:
      getStageBounds in interface Graphic2D
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLocation

      public DisplayListLocation getLocation()
      Description copied from interface: Graphic2D
      Returns the DisplayListLocation attached to this graphic, which is used by the renderer to determine how this graphic should be drawn.
      Specified by:
      getLocation in interface Graphic2D