API Docs for:
Show:

Renderer Class

Defined in: src/renderer.js:4

Renders the current game state using html5 canvas.

Constructor

Renderer

(
  • game
  • width
  • height
  • tileSize
  • [canvasClassName='renderer']
)

Defined in src/renderer.js:4

Parameters:

  • game Game
    • Game instance this obj is attached to.
  • width Number
    • Width of the map view in tiles.
  • height Number
    • Height of the map view in tiles.
  • tileSize Number
    • Width and height of tiles when drawn.
  • [canvasClassName='renderer'] String optional
    • Css class name for the canvas element.

Methods

draw

()

Defined in src/renderer.js:219

Draws map and entity tiles. All parameters will fall back to this.game. if not provided.

drawBufferToCanvas

()

Defined in src/renderer.js:425

Copies pixel data from the buffer canvas to the game canvas.

drawTileToCanvas

(
  • x
  • y
  • tileData
  • [ctx=this.bufferCtx]
)

Defined in src/renderer.js:261

Draws a single tile to the map view.

Parameters:

  • x Number
    • Map tile coord on the x axis.
  • y Number
    • Map tile coord on the y axis.
  • tileData Object
    • Object containing tile draw settings.
    • [char] Object optional
      • The character to draw.
    • [color] Object optional
      • The color of the character displayed.
    • [bgColor] Object optional
      • The background color of the tile.
    • [borderColor] Object optional
      • The border color of the tile.
    • [borderWidth=1] Object optional
      • The border width of the tile.
  • [ctx=this.bufferCtx] CanvasRenderingContext2D optional
    • The canvas context to draw to.

fillBg

(
  • [color=this.bgColor]
  • [ctx=this.bufferCtx]
)

Defined in src/renderer.js:408

Fills the canvas with a given color.

Parameters:

  • [color=this.bgColor] String optional
  • [ctx=this.bufferCtx] CanvasRenderingContext2D optional

mouseToTileCoords

(
  • x
  • y
)
Object | False

Defined in src/renderer.js:368

Converts mouse pixel coords to map tile coords. Mouse pixel coords must be relative to the current window.

Parameters:

  • x Number
    • Mouse pixel x coord.
  • y Number
    • Mouse pixel y coord.

Returns:

Object | False:

{x: 0, y: 0}

pixelToTileCoords

(
  • x
  • y
)
Object | False

Defined in src/renderer.js:382

Converts map view pixel coords to map tile coords. Map view pixel coords are relative to the top left of the canvas element.

Parameters:

  • x Number
    • Map view pixel x coord.
  • y Number
    • Map view pixel y coord.

Returns:

Object | False:

{x: 0, y: 0}

resize

()

Defined in src/renderer.js:178

Resizes canvas elements to match the tileSize and map view with/height. Also adjusts behavior to accomodate high pixel density screens.

setCenter

(
  • centerX
  • centerY
)

Defined in src/renderer.js:396

Sets the center map tile of the view.

Parameters:

  • centerX Number
    • Center map tile x coord.
  • centerY Number
    • Center map tile y coord.

Properties

bgColor

String

Defined in src/renderer.js:71

Background color of map view.

buffer

HTMLCanvasElement

Defined in src/renderer.js:57

Canvas element this renderer draws to as a buffer for this.canvas.

bufferCtx

CanvasRenderingContext2D

Defined in src/renderer.js:64

Drawing context of this.buffer

canvas

HTMLCanvasElement

Defined in src/renderer.js:43

Canvas element this renderer draws to.

ctx

CanvasRenderingContext2D

Defined in src/renderer.js:50

Drawing context of this.canvas

devicePixelRatio

Number

Defined in src/renderer.js:106

Device pixel ratio for high dpi screens.

font

String

Defined in src/renderer.js:99

Font used to render tile characters.

game

Game

Defined in src/renderer.js:30

Game instance this obj is attached to.

height

Number

Defined in src/renderer.js:120

Map view height in tiles.

hoverColor

String

Defined in src/renderer.js:78

Color overlayed when mouse is over a tile.

hoveredTileX

Number | Null

Defined in src/renderer.js:155

The map tile x coord of the tile currently being hovered by the mouse.

hoveredTileY

Number | Null

Defined in src/renderer.js:162

The map tile y coord of the tile currently being hovered by the mouse.

nonVisibleTileAlpha

Number

Defined in src/renderer.js:85

Alpha value applied to non-visible tiles

offsetX

Number

Defined in src/renderer.js:127

The x distance in tiles from center to upper left corner of map view.

offsetY

Number

Defined in src/renderer.js:134

The y distance in tiles from center to upper left corner of map view.

originX

Number

Defined in src/renderer.js:141

The map tile x coord of the tile drawn in the upper left corner of the map view.

originY

Number

Defined in src/renderer.js:148

The map tile y coord of the tile drawn in the upper left corner of the map view.

tileSize

Number

Defined in src/renderer.js:92

Size of each tile is drawn.

width

Number

Defined in src/renderer.js:113

Map view width in tiles.