API Docs for:
Show:

View Class

Defined in: rendering\View.js:1

This object is used by various systems for drawing on a canvas. It provides the most basic amount of information required for rendering and should be wrapped by a custom camera object. The view takes its height and width from the canvas object directly, so it will always allow for rendering on the whole canvas.

Constructor

View

(
  • canvas
)

Defined in rendering\View.js:1

Parameters:

  • canvas Canvas

    Canvas object to be drawn to.

Methods

applyViewTransform

()

Applies the view scaling and translation to the context. The transform should be applied before doing any other transformations.

clearContext

()

Clears the whole canvas.

getContext

()

Returns:

2D context used for rendering.

getGameHeight

()

Returns:

Height of the game space.

getGameWidth

()

Returns:

Width of the game space.

getPosition

(
  • vector
)

Parameters:

  • vector Vector2D

    The vector to which the position will be copied.

getViewHeight

()

Returns:

Height of the view.

getViewWidth

()

Returns:

Width of the view.

resetContextTransform

()

Sets the context's transformation matrix to an identity matrix.

setGameHeight

(
  • height
)

Sets the height of the game space.

Parameters:

  • height Number

    New height of the game space.

setGameWidth

(
  • width
)

Sets the width of the game space.

Parameters:

  • width Number

    New width of the game space.

setPosition

(
  • x
  • y
)

Sets a new position for the view. The view's position is its middle point. The view's top left corner's position can never be less than 0 on either axis, this function ensures that. This limitation makes tile rendering logic much less complicated.

Parameters:

  • x Number

    The x component of the new position.

  • y Number

    The y component of the new position.

setViewHeight

(
  • height
)

Sets the height of the view. The view always renders to the full canvas, so setting the height to something other than the height of the canvas will scale the rendered output.

Parameters:

  • height Number

    New height of the view.

setViewWidth

(
  • width
)

Sets the width of the view. The view always renders to the full canvas, so setting the width to something other than the width of the canvas will scale the rendered output.

Parameters:

  • width Number

    New width of the view.