camera.zoom

Category:Game Lab

The zoom factor of the camera.

A zoom of 1 is the default, normal size. Setting zoom to 2 will zoom in and make everything twice the size. Setting zoom to 0.5 will zoom out make everything half size. All camera properties can be both accessed and updated.

The camera enables scrolling and zooming for scenes extending beyond the display area. A camera has a position, a zoom factor, and mouse coordinates relative to the view. The camera is automatically created and available for use.

Examples

Near and Far

Zoom in and out.

// Zoom in and out.
var back = createSprite(200, 200);
back.setAnimation("stone_snow_1");
camera.on();

function draw() {
  background("white");
  drawSprites();
  if (keyDown("up")) {
    camera.zoom = camera.zoom - 0.1;
  }
  if (keyDown("down")) {
    camera.zoom = camera.zoom + 0.1;
  } 
}

Syntax

camera.zoom

Returns

The zoom factor of the camera.

Tips

  • The display area is 400 pixels x 400 pixels and the upper left corner is (0.0).
  • To access or update the camera properties you use the dot notation (camera, followed by a dot, with the label of the property).
  • Any changes to the properties of the camera will not be seen until after drawSprites() is called.

Found a bug in the documentation? Let us know at documentation@code.org