Camera

Camera

new Camera()

Look at the Camera reference pages before reading these docs. A `camera` object is created automatically when p5play loads. Currently, there can only be one camera per sketch (instance of p5 or q5). A camera facilitates zooming and scrolling for scenes extending beyond the canvas. Moving the camera does not actually move the sprites. The camera is automatically created on the first draw cycle. The camera wraps the whole drawing cycle in a transformation matrix (using `push`/`pushMatrix`) but it can be disabled during the draw cycle to draw interface elements in an absolute position.
Source:

Classes

Camera

Members

pos :Object

The camera's position. {x, y}
Source:
Type:
  • Object

position :Object

The camera's position. Alias for pos.
Source:
Type:
  • Object

x :Number

The camera x position.
Source:
Type:
  • Number

y :Number

The camera y position.
Source:
Type:
  • Number

zoom :Number

Camera zoom. A scale of 1 will be the normal size. Setting it to 2 will make everything appear twice as big. .5 will make everything look half size.
Default Value:
  • 1
Source:
Type:
  • Number

Methods

moveTo(x, y, speed) → {Promise}

Moves the camera to a position. Similar to `sprite.moveTo`.
Source:
Parameters:
Name Type Description
x Number
y Number
speed Number
Returns:
Type:
Promise
resolves true when the camera reaches the target position

off()

Deactivates the camera. The canvas will be drawn normally, ignoring the camera's position and scale until camera.on() is called.
Source:

on()

Activates the camera. The canvas will be drawn according to the camera position and scale until camera.off() is called.
Source:

zoomTo(target, speed) → {Promise}

Zoom the camera at a given speed.
Source:
Parameters:
Name Type Description
target Number The target zoom
speed Number The amount of zoom per frame
Returns:
Type:
Promise
resolves true when the camera reaches the target zoom