API Docs for: 0.3.0
Show:

Graphic.Camera Class

The Camera class allow you to create a camera who has the purpose to simulate a camera on some layers. Each Layer or Window contain a camera for moving te point of view displayed.

Manipulate the camera

The movement of the camera is based on an internal matrix, representing the point of view of the camera. This class provide an useful way to moving in the space without using directly matrices. All manipulation methods matrix provided are applied in a fixed order:

  • translation
  • rotation
  • skew
  • scale

the aim is to use each type of transformation separately, regardless of the order of method calls.

It's also possible to directly use the matrix methods, but both methods are not compatible, because calling a method from the camera will overwrite the matrix.
If you choose to directly manipulate the matrix, be careful to not use matrix transformations method provided by the Camera class.

Extending the class

The Camera class provide only basic features and is destined to be extended. The two important methods are prepare and update

  • prepare is called for preparing the graphic rendering (just applying matrix by default).
    More information here
  • update is an optional method (and is not provided in this class) called regularly, useful for adding a dynamic behavior.
    Note that you can take advantage of Javascript by adding directly an update method on the Camera instance.

Constructor

Graphic.Camera

()

Item Index

Properties

Methods

_updateMatrix

() protected

Update the matrix after a transformation.

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

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.