Package dev.kyzel.gfx

Class Renderer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class Renderer extends JPanel
A class to handle drawing stuff to the screen.
See Also:
  • Field Details

    • width

      private int width
      The width and height of this instance.
    • height

      private int height
      The width and height of this instance.
    • originalUnitSize

      private final int originalUnitSize
      The unit size of sprites.
      See Also:
    • scale

      private final int scale
      The desired scale.
      See Also:
    • unitSize

      private final int unitSize
      The actual unit size of sprites after scaling.
      See Also:
    • FPS

      private final int FPS
      The frame rate (FPS).
    • game

      private final Game game
      The game to render.
    • gameImage

      private BufferedImage gameImage
      The main BufferedImage, which the Renderer uses to draw on.
  • Constructor Details

    • Renderer

      public Renderer(int width, int height, int FPS)
      Creates a new Renderer.
      Parameters:
      width - the width of the drawing canvas
      height - the height of the drawing canvas
      FPS - the desired frame rate (FPS)
  • Method Details

    • getGameImageGraphics

      public Graphics getGameImageGraphics()
      Creates a graphics context of gameImage.
      Returns:
      the graphics context of gameImage
    • getFPS

      public int getFPS()
      Gets the frame rate (FPS).
      Returns:
      the frame rate (FPS)
    • getUnitScale

      public int getUnitScale()
      Gets the scale of unit size
      Returns:
      the scale of unit size
    • getUnitSize

      public int getUnitSize()
      Gets the actual unit size
      Returns:
      the actual unit size
    • getWidth

      public int getWidth()
      Gets the width of this instance.
      Overrides:
      getWidth in class JComponent
      Returns:
      the width of this instance
    • getHeight

      public int getHeight()
      Gets the height of this instance.
      Overrides:
      getHeight in class JComponent
      Returns:
      the height of this instance
    • drawToScreen

      public void drawToScreen()
      Draws the gameImage to the window.
    • setAttributes

      public void setAttributes(int width, int height)
      Set the attributes of this instance to match with the new width and height.
      Parameters:
      width - the new width
      height - the new height