API Docs for: 3
Show:

Camera Class

Defined in: v3/p5play.js:5667

Look at the Camera reference pages before reading these docs.

https://p5play.org/learn/camera.html

A camera object is created automatically when p5play loads. Currently, there can only be one camera per p5.js instance.

A camera facilitates scrolling and zooming for scenes extending beyond the canvas. A camera has a position, a zoom factor, and the mouse coordinates relative to the view. The camera is automatically created on the first draw cycle.

In p5.js terms the camera wraps the whole drawing cycle in a transformation matrix but it can be disable anytime during the draw cycle for example to draw interface elements in an absolute position.

Constructor

Camera

(
  • x
  • y
  • zoom
)

Defined in v3/p5play.js:5667

Parameters:

  • x Number

    Initial x coordinate

  • y Number

    Initial y coordinate

  • zoom Number

    magnification

Item Index

Methods

Methods

off

()

Defined in v3/p5play.js:5819

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

on

()

Defined in v3/p5play.js:5803

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

Properties

active

Boolean

Defined in v3/p5play.js:5732

True if the camera is active. Read only property. Use the methods Camera.on() and Camera.off() to enable or disable the camera.

Default: false

mouse

Object

Defined in v3/p5play.js:5710

Get the translated mouse position relative to the camera view. Offsetting and scaling the canvas will not change the sprites' position nor the mouseX and mouseY variables. Use this property to read the mouse position if the camera moved or zoomed.

mouse.x

Number

Defined in v3/p5play.js:5723

mouse.y

Number

Defined in v3/p5play.js:5727

pos

Object

Defined in v3/p5play.js:5752

The camera's position. {x, y}

position

Object

Defined in v3/p5play.js:5761

The camera's position. Alias for pos.

x

Number

Defined in v3/p5play.js:5771

The camera x position.

y

Number

Defined in v3/p5play.js:5787

The camera y position.

zoom

Number

Defined in v3/p5play.js:5697

Camera zoom.

A scale of 1 will be the normal size. Setting it to 2 will make everything twice the size. .5 will make everything half size.

Default: 1