Class Renderer

Class represents Game Renderer.

Hierarchy

  • Renderer

Constructors

Properties

canvasParentSize: number = 1

The decimal midpoint of parent element size.

gridSize: number = 0

How many pixels have one grid unit.

handler: Game

Renderer owner.

Accessors

  • get canvasHeight(): number
  • Gets canvas height in pixels.

    Returns number

  • set canvasHeight(height: number): void
  • Sets canvas height in pixels.

    Parameters

    • height: number

      The new height

    Returns void

  • get canvasWidth(): number
  • Gets canvas width in pixels.

    Returns number

  • set canvasWidth(width: number): void
  • Sets canvas width in pixels.

    Parameters

    • width: number

      The new width

    Returns void

  • get ctx(): CanvasRenderingContext2D
  • Gets the CanvasRenderingContext2D.

    Returns CanvasRenderingContext2D

Methods

  • Clears the canvas.

    Method

    Example

    renderer.clearFrame();
    

    Returns void

  • Combines given draw settings with default draw settings.

    Method

    Returns

    The combined draw settings

    Example

    const drawSettings = renderer.combineDrawSettings({ color: 'red' });
    

    Parameters

    • drawSettings: undefined | DrawSettings

      The given draw settings

    Returns DrawSettings

  • Draws arrow from position to another position.

    Method

    Example

    renderer.drawArrow(2, 3, 3, 4);
    

    Parameters

    • fromWorldX: number

      From X-coordinate

    • fromWorldY: number

      From Y-coordinate

    • toWorldX: number

      To X-coordinate

    • toWorldY: number

      To Y-coordinate

    • Optional drawSettings: DrawSettings

      The draw settings

    Returns void

  • Draws a circle.

    Method

    Example

    renderer.drawCircle(0, 0, 1, { color: 'yellow' });
    

    Parameters

    • worldX: number

      The X-coordinate

    • worldY: number

      The Y-coordinate

    • diameter: number

      The diameter

    • Optional drawSettings: DrawSettings

      The draw settings

    Returns void

  • Draws hitbox with direction arrow.

    Method

    Example

    const exampleClickableObject = ...;
    renderer.drawHitbox(exampleClickableObject);

    Parameters

    Returns void

  • Draws image.

    Method

    Example

    renderer.drawImage(game.GetImage('player'), 0, 0, 1, 1, { angle: 45 });
    

    Parameters

    • image: HTMLImageElement

      The image

    • worldX: number

      The X-coordinate

    • worldY: number

      The Y-coordinate

    • worldWidth: number

      The width

    • worldHeight: number

      The height

    • Optional drawSettings: DrawSettings

      The draw settings

    Returns void

  • Draws line from position to another position.

    Method

    Example

    renderer.drawLine(2, 3, 3, 4);
    

    Parameters

    • fromWorldX: number

      From X-coordinate

    • fromWorldY: number

      From Y-coordinate

    • toWorldX: number

      To X-coordinate

    • toWorldY: number

      To Y-coordinate

    • Optional drawSettings: DrawSettings

      The draw settings

    Returns void

  • Draws a rect.

    Method

    Example

    renderer.drawRectangle(5, 2, 1, 1, { color: 'green', border: true });
    

    Parameters

    • worldX: number

      The X-coordinate

    • worldY: number

      The Y-coordinate

    • worldWidth: number

      The width

    • worldHeight: number

      The height

    • Optional drawSettings: DrawSettings

      The draw settings

    Returns void

  • Draws sprite texture.

    Method

    Returns

    is success?

    Example

    const exampleSprite = ...;
    renderer.drawSprite(exampleSprite);

    Parameters

    Returns boolean

  • Fills canvas with content.

    Method

    Example

    renderer.fill('white');
    renderer.fill({ color: 'white' })
    renderer.fill(game.GetImage('background'));

    Parameters

    Returns void

  • Fills canvas with image.

    Deprecated

    Parameters

    • image: HTMLCanvasElement

      The image

    Returns void

  • Resizes canvas to parent element size by canvasParentSize (decimal midpoint).

    Method

    Example

    renderer.resizeCanvas();
    

    Returns void

  • Scales number from client coordinate to grid coordinate.

    Method

    Returns

    The scaled number

    Example

    const scaledToGrid = renderer.scale(5);
    

    Parameters

    • a: number

      The client coordinate

    Returns number