Camera Movement

The camera is center positioned and located in the middle of the canvas by default.

The camera can be moved by changing its x and y values or by using the moveTo function.

If you want the camera to follow a sprite, move the camera in the q5.draw function, which runs after the physics simulation is updated.

In this example the camera follows the player's x axis movement.

Camera Zoom

zoom changes the scale that sprites and other elements in the world are drawn at. Increasing the zoom will make sprites appear larger, and decreasing the zoom will make sprites appear smaller.

zoomTo(target, speed) is an async function that can be used to smoothly zoom the camera in and out. It takes an optional second parameter, the amount it will zoom per frame.

Camera On & Off

By default, the camera is turned on after the end of q5.draw before allSprites.draw() is run, then the camera gets turned off before q5.postProcess is run.

The player and environment of your game should be drawn after the camera is turned on with camera.on().

UI or HUD sprites, represented by orange squares in this examples, should be drawn after the camera is turned off with camera.off().

Only sprites with an image, animation, or custom draw function can be drawn manually. Collider shapes are drawn only during q5play's debug draw phase.

Previous Page Next Page