Class Java2DRenderer

  • All Implemented Interfaces:
    Renderer
    Direct Known Subclasses:
    HeadlessRenderer

    public class Java2DRenderer
    extends java.lang.Object
    implements Renderer
    Implementation of a renderer that uses APIs from the Java standard library. Graphics are displayed using Java 2D, AWT is used to create windows and capture keyboard events, and Java Sound is used to play audio.

    The renderer will use two different threads: the rendering thread is used to update the graphics, while the Swing thread is used to listen for user input.

    • Constructor Detail

      • Java2DRenderer

        public Java2DRenderer​(Canvas canvas,
                              int framerate,
                              WindowOptions options)
    • Method Detail

      • start

        public void start()
        Specified by:
        start in interface Renderer
      • initializeWindow

        protected javax.swing.JFrame initializeWindow​(WindowOptions windowOptions)
      • drawFrame

        protected void drawFrame​(java.awt.Graphics2D g2)
      • prepareCanvas

        protected void prepareCanvas()
      • prepareWindowBuffer

        protected java.awt.image.BufferStrategy prepareWindowBuffer()
        Prepares the window buffer for the current frame. This buffer will be used to display the graphics once the entire frame has been rendered.
      • blitGraphicsContext

        protected void blitGraphicsContext​(java.awt.image.BufferStrategy windowBuffer)
        Updates the window graphics with the contents of the buffer.
      • takeScreenshot

        public java.lang.String takeScreenshot()
        Description copied from interface: Renderer
        Takes a screenshots of the renderer's current graphics, and saves it to an image. The image is returned as a data URL for a PNG image.
        Specified by:
        takeScreenshot in interface Renderer
      • getPlatform

        public nl.colorize.util.PlatformFamily getPlatform()
        Specified by:
        getPlatform in interface Renderer
      • terminate

        public void terminate()