View Class
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
Parameters:
-
canvas
CanvasCanvas object to be drawn to.
Item Index
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:
getGameHeight
()
Returns:
getGameWidth
()
Returns:
getViewHeight
()
Returns:
getViewWidth
()
Returns:
resetContextTransform
()
Sets the context's transformation matrix to an identity matrix.
setGameHeight
-
height
Sets the height of the game space.
Parameters:
-
height
NumberNew height of the game space.
setGameWidth
-
width
Sets the width of the game space.
Parameters:
-
width
NumberNew 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
NumberThe x component of the new position.
-
y
NumberThe 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
NumberNew 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
NumberNew width of the view.