Interface SceneContext


public interface SceneContext
The currently active scene (and its sub-scenes) receive access to the scene context, which is provided by the renderer via callback methods. This allows the scene to access the underlying renderer and the stage.

The stage contains the graphics and audio for the currently active scene. The stage can contain both 2D and 3D graphics, depending on what is supported by the renderer. At the end of a scene, the stage is cleared so the next scene can take over.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    attach(Runnable callback)
    Attaches a sub-scene, based on the specified callback, to the currently active scene.
    default void
    attach(Scene subScene)
    Attaches a sub-scene to the currently active scene.
    default void
    attach(Updatable callback)
    Attaches a sub-scene, based on the specified callback, to the currently active scene.
    default void
    attach(Updatable onFrame, BooleanSupplier completed, Runnable onComplete)
    Creates a sub-scene using the specified callback methods, then attaches that sub-scene to the currently active scene.
    default <T> nl.colorize.util.Subject<T>
    attach(nl.colorize.util.EventQueue<T> eventQueue)
    Attaches a sub-scene that processes an EventQueue during frame updates.
    default <T> void
    attach(nl.colorize.util.EventQueue<T> events, Consumer<T> onEvent, Consumer<Exception> onError)
    Attaches a sub-scene that processes an EventQueue using the provided callback functions.
    default void
    Attaches a sub-scene that will invoke the specified callback function when the specified graphics are clicked.
    default void
    attachGlobalSubScene(Scene globalSubScene)
    Attaches a sub-scene that is not tied to the currently active scene, and will remain active for as long as the application is active.
    default void
    attachTimeline(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback)
    Attaches a sub-scene that will (A) update the timeline during every frame update, (B) invoke the callback function with the timeline's value.
    default void
    attachTimeline(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback, Runnable onComplete)
    Attaches a sub-scene that will (A) update the timeline during every frame update, (B) invoke the callback function with the timeline's value.
    default void
    attachTimer(float delay, Runnable callback)
    Attaches a sub-scene that will (A) update the timer during every frame update, (B) invoke the specified callback function exactly once when the timer has completed.
    default void
    attachTimer(Timer timer, Runnable callback)
    Attaches a sub-scene that will (A) update the timer during every frame update, (B) invoke the specified callback function exactly once when the timer has completed.
    boolean
    castPickRay(Point2D canvasPosition, Box area)
    Casts a pick ray from the specified 2D canvas position, and returns true if the pick ray intersects with the specified 3D world coordinates.
    default void
    changeScene(Scene requestedScene)
    Requests to change the active scene after the current frame update has been completed.
    default Mesh
    Programmatically creates a 3D polygon mesh that initially does not have any color or texture information attached to it.
    createMesh(Shape3D shape, ColorRGB color)
    Programmatically creates a 3D polygon mesh with a solid color, based on the specified shape.
    default Canvas
     
     
    default List<String>
    Returns debug and support information that can be displayed when running a MultimediaLib application in debug mode.
    default FrameStats
     
     
     
     
    Returns the display name for the underlying renderer.
     
     
    project(Point3D position)
    Returns the 3D world coordinates that correspond to the specified 2D canvas coordinates, based on the current camera position.
    void
    takeScreenshot(File screenshotFile)
    Captures a screenshot of the renderer's current graphics and then exports the screenshot to a PNG file.
    void
    Terminates the renderer, which will end the animation loop and quit the application.
  • Method Details

    • getConfig

      RenderConfig getConfig()
    • getCanvas

      default Canvas getCanvas()
    • getMediaLoader

      MediaLoader getMediaLoader()
    • getInput

      InputDevice getInput()
    • getNetwork

      Network getNetwork()
    • getSceneManager

      SceneManager getSceneManager()
    • getStage

      Stage getStage()
    • getFrameStats

      default FrameStats getFrameStats()
    • changeScene

      default void changeScene(Scene requestedScene)
      Requests to change the active scene after the current frame update has been completed. If another scene had already been requested, calling this method again will overrule that request.
    • attach

      default void attach(Scene subScene)
      Attaches a sub-scene to the currently active scene. The sub-scene will remain active until Scene.isCompleted() returns true or the parent scene ends.
      See Also:
    • attach

      default void attach(Updatable onFrame, BooleanSupplier completed, Runnable onComplete)
      Creates a sub-scene using the specified callback methods, then attaches that sub-scene to the currently active scene. The sub-scene will remain active until completed returns true or the parent scene ends.
      See Also:
    • attach

      default void attach(Updatable callback)
      Attaches a sub-scene, based on the specified callback, to the currently active scene. The sub-scene will remain active until the parent scene ends.
    • attach

      default void attach(Runnable callback)
      Attaches a sub-scene, based on the specified callback, to the currently active scene. The sub-scene will remain active until the parent scene ends.
    • attach

      default <T> void attach(nl.colorize.util.EventQueue<T> events, Consumer<T> onEvent, Consumer<Exception> onError)
      Attaches a sub-scene that processes an EventQueue using the provided callback functions. This ensures asynchronous events are processed during frame updates, instead of when they are received.
    • attach

      default <T> nl.colorize.util.Subject<T> attach(nl.colorize.util.EventQueue<T> eventQueue)
      Attaches a sub-scene that processes an EventQueue during frame updates. This returns a Subject that only publishes events during frame updates, instead of publishing events whenever they arrive.
    • attachTimer

      default void attachTimer(Timer timer, Runnable callback)
      Attaches a sub-scene that will (A) update the timer during every frame update, (B) invoke the specified callback function exactly once when the timer has completed. This method is effectively performing an action with a time delay.
    • attachTimer

      default void attachTimer(float delay, Runnable callback)
      Attaches a sub-scene that will (A) update the timer during every frame update, (B) invoke the specified callback function exactly once when the timer has completed. This method is effectively performing an action with a time delay.
    • attachTimeline

      default void attachTimeline(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback, Runnable onComplete)
      Attaches a sub-scene that will (A) update the timeline during every frame update, (B) invoke the callback function with the timeline's value. The sub-scene will run until the timeline is completed.
    • attachTimeline

      default void attachTimeline(nl.colorize.util.animation.Timeline timeline, Consumer<Float> callback)
      Attaches a sub-scene that will (A) update the timeline during every frame update, (B) invoke the callback function with the timeline's value. The sub-scene will run until the timeline is completed.
    • attachClickHandler

      default void attachClickHandler(StageNode2D node, Runnable callback)
      Attaches a sub-scene that will invoke the specified callback function when the specified graphics are clicked.

      Note: This should be called "pointer released handler", since it also supports touch events. The term "click handler" exists for historic reasons.

    • attachGlobalSubScene

      default void attachGlobalSubScene(Scene globalSubScene)
      Attaches a sub-scene that is not tied to the currently active scene, and will remain active for as long as the application is active.
      See Also:
    • createMesh

      Mesh createMesh(Shape3D shape, ColorRGB color)
      Programmatically creates a 3D polygon mesh with a solid color, based on the specified shape.
      Throws:
      UnsupportedOperationException - if this renderer does not support 3D graphics.
    • createMesh

      default Mesh createMesh(Shape3D shape)
      Programmatically creates a 3D polygon mesh that initially does not have any color or texture information attached to it. The mesh can be modified after creation using Mesh.applyColor(ColorRGB) and Mesh.applyTexture(Image) respectively.
      Throws:
      UnsupportedOperationException - if this renderer does not support 3D graphics.
    • project

      Point2D project(Point3D position)
      Returns the 3D world coordinates that correspond to the specified 2D canvas coordinates, based on the current camera position.
      Throws:
      UnsupportedOperationException - if this renderer does not support 3D graphics.
    • castPickRay

      boolean castPickRay(Point2D canvasPosition, Box area)
      Casts a pick ray from the specified 2D canvas position, and returns true if the pick ray intersects with the specified 3D world coordinates.
      Throws:
      UnsupportedOperationException - if this renderer does not support 3D graphics.
    • takeScreenshot

      void takeScreenshot(File screenshotFile)
      Captures a screenshot of the renderer's current graphics and then exports the screenshot to a PNG file.
      Throws:
      UnsupportedOperationException - if this renderer does not support taking screenshots at runtime.
    • terminate

      void terminate()
      Terminates the renderer, which will end the animation loop and quit the application.
      Throws:
      UnsupportedOperationException - if the current platform does not support terminating applications.
    • getRendererName

      String getRendererName()
      Returns the display name for the underlying renderer. The display name will not include the word "renderer".
    • getDebugInformation

      default List<String> getDebugInformation()
      Returns debug and support information that can be displayed when running a MultimediaLib application in debug mode. The returned list is intended to be displayed in a Text, which can be styled to match the application appearance.