API Docs for: 0.3.0
Show:

Graphic.TrackingCamera Class

the TrackingCamera is a Camera which can follow a target.

When the target near the edges of the camera, the camera move for always keep the target in the field of view. This behaviour can be enabled or disabled whith lock.

The margin property provides a way to configure the motion field of the player. If we set the margin.x to 10, the camera don't let the player to approach whitin 10px.

Constructor

Graphic.TrackingCamera

(
  • target
)

Parameters:

  • target GraphicObject

Methods

_updateMatrix

() protected

Update the matrix after a transformation.

draw

()

Update the camera position. If locked and the target go out of camera, the camera follow the target.

prepare

(
  • context
)

prepare is called before each draw on the canvas. The canvas 2D context must be completely reset.

By default, context matrix are multiplied by internal matrix. save and restore operations are done by the caller.

Parameters:

  • context CanvasRenderingContext2D

    The canvas context which will be used to draw.

rotate

(
  • angle
)
Camera chainable

Apply a rotation to the camera.

Parameters:

  • angle Number

    rotation angle in degrees.

Returns:

Camera:

scale

(
  • x
  • y
)
Camera chainable

Apply a scale transformation to the camera.

Parameters:

  • x Number
  • y Number

Returns:

Camera:

skew

(
  • a
  • b
)
Camera chainable

Apply a skew transformation to the camera.

Parameters:

  • a Number
  • b Number

Returns:

Camera:

translate

(
  • x
  • y
)
Camera chainable

Apply a translation to the camera.

Parameters:

  • x Object
  • y Object

Returns:

Camera:

Properties

locked

Boolean

Lock or not the camera on the target.

Default: true

margin

Object

inner screen margin

Sub-properties:

  • x Number
  • y Number

matrix

Matrix2D

matrix used for define the view.

Note that modify it don't automatically refresh the associated layer. You should refresh the Layer after this operation.

Directly modifing the matrix is not compatible with other matrix Camera's method (translate, rotate, skew or scale). Calling one of these method will recreate the matrix and erasing your matrix. For applying transformations, you should modify directly the matrix.

target

GraphicObject

target pointed by the camera