Class Stage

java.lang.Object
nl.colorize.multimedialib.stage.Stage
All Implemented Interfaces:
StageSubscriber

public final class Stage extends Object implements StageSubscriber
The stage contains the graphics and audio for the currently active scene. The stage can contain both 2D and 3D graphics. It is structured as a scene graph, where transforming a parent node propagates to its children.

While the scene has full control over the stage, this control cannot outlive the scene itself: at the end of the scene the contents of the stage are cleared so the next scene can take over.

  • Field Details

    • DEFAULT_AMBIENT_LIGHT_COLOR

      public static final ColorRGB DEFAULT_AMBIENT_LIGHT_COLOR
  • Constructor Details

    • Stage

      public Stage(GraphicsMode graphicsMode, Canvas canvas)
      Creates a new stage that will be drawn to the specified canvas, using the specified graphics mode.
  • Method Details

    • onNodeAdded

      public void onNodeAdded(Container parent, StageNode2D node)
      Specified by:
      onNodeAdded in interface StageSubscriber
    • onNodeRemoved

      public void onNodeRemoved(Container parent, StageNode2D node)
      Specified by:
      onNodeRemoved in interface StageSubscriber
    • onNodeAdded

      public void onNodeAdded(Group parent, StageNode3D node)
      Specified by:
      onNodeAdded in interface StageSubscriber
    • onNodeRemoved

      public void onNodeRemoved(Group parent, StageNode3D node)
      Specified by:
      onNodeRemoved in interface StageSubscriber
    • addContainer

      public Container addContainer()
      Creates a new container, then adds it to the root of the scene graph. Returns the container that was just created. This is a convenience method to easily create top-level containers.
    • addContainer

      public Container addContainer(String name)
      Creates a new container with the specified name, then adds it to the root of the scene graph. Returns the container that was just created. This is a convenience method to easily create top-level containers.
    • addGroup

      public Group addGroup(String name)
      Creates a new group with the specified name, then adds it to the root container for 3D graphics to make it part of the stage.
    • detach

      public void detach(StageNode2D node)
      Detaches the specified node from the scene graph. If the node is not currently part of the stage, calling this method does nothing.

      Prefer using Container.removeChild(StageNode2D) over this method, as it has better performance. This method exists for convenience, as it does not require references to both parent and child, and can be used in situations that are not performance-critical.

    • detach

      public void detach(StageNode3D node)
      Detaches the specified node from the scene graph. If the node is not currently part of the stage, calling this method does nothing.

      Prefer using Group.removeChild(StageNode3D) over this method, as it has better performance. This method exists for convenience, as it does not require references to both parent and child, and can be used in situations that are not performance-critical.

    • clear

      public void clear()
      Removes all 2D and 3D graphics from the stage. This is always called at the end of a scene, but can also be used manually mid-scene.
    • visit

      public void visit(StageVisitor visitor)
      Visits all nodes that are currently part of the stage. Nodes will be visited in the order in which they should be drawn. Parent nodes will be visited before their children.
    • subscribe

      public void subscribe(StageSubscriber subscriber)
      Subscribes to this stage, receiving events every time nodes are added or removed.
    • findNodePath

      public List<StageNode2D> findNodePath(StageNode2D node)
      Returns the path towards the specified node. The first element in the list is the root node, the last element is the node itself. If the node is not currently part of the stage, this returns a list containing only the node itself.
    • findNodePath

      public List<StageNode3D> findNodePath(StageNode3D node)
      Returns the path towards the specified node. The first element in the list is the root node, the last element is the node itself. If the node is not currently part of the stage, this returns a list containing only the node itself.
    • recalculateGlobalTransform

      public void recalculateGlobalTransform(StageNode2D node)
      Recalculates the global transform for the specified node. The global transform is normally updated at the end of each frame update when the node is drawn. This method can be used to force-recalculate the global transform for a single node.

      Since the global transform is relative to the node's parent, this will also recalculate the global transform for its parents, recursively. This method therefore has a performance impact, and should only be used on/for a limited number of nodes per frame update.

    • recalculateGlobalTransform

      public void recalculateGlobalTransform(StageNode3D node)
      Recalculates the global transform for the specified node. The global transform is normally updated at the end of each frame update when the node is drawn. This method can be used to force-recalculate the global transform for a single node.

      Since the global transform is relative to the node's parent, this will also recalculate the global transform for its parents, recursively. This method therefore has a performance impact, and should only be used on/for a limited number of nodes per frame update.

    • toString

      public String toString()
      Returns a textual representation of the stage's current contents, which can be used for testing and debugging purposes.
      Overrides:
      toString in class Object
    • getGraphicsMode

      public GraphicsMode getGraphicsMode()
    • getCanvas

      public Canvas getCanvas()
    • getAnimationTimer

      public Timer getAnimationTimer()
    • getRoot

      public Container getRoot()
    • getBackgroundColor

      public ColorRGB getBackgroundColor()
    • getParentMap2D

      public Map<StageNode2D,Container> getParentMap2D()
    • getRoot3D

      public Group getRoot3D()
    • getCameraPosition

      public Point3D getCameraPosition()
    • getCameraFocus

      public Point3D getCameraFocus()
    • getAmbientLightColor

      public ColorRGB getAmbientLightColor()
    • getParentMap3D

      public Map<StageNode3D,Group> getParentMap3D()
    • setBackgroundColor

      public void setBackgroundColor(ColorRGB backgroundColor)
    • setParentMap2D

      public void setParentMap2D(Map<StageNode2D,Container> parentMap2D)
    • setCameraPosition

      public void setCameraPosition(Point3D cameraPosition)
    • setCameraFocus

      public void setCameraFocus(Point3D cameraFocus)
    • setAmbientLightColor

      public void setAmbientLightColor(ColorRGB ambientLightColor)
    • setParentMap3D

      public void setParentMap3D(Map<StageNode3D,Group> parentMap3D)