Camera#

arcade.Camera#

class arcade.Camera(viewport_width: int = 0, viewport_height: int = 0, window: Optional[arcade.application.Window] = None)[source]#

The Camera class is used for controlling the visible viewport. It is very useful for separating a scrolling screen of sprites, and a GUI overlay. For an example of this in action, see Move with a Scrolling Screen - Centered.

Parameters
  • viewport_width (int) – Width of the viewport. If not set the window width will be used.

  • viewport_height (int) – Height of the viewport. If not set the window height will be used.

  • window (Window) – Window to associate with this camera, if working with a multi-window program.

property anchor: Optional[Tuple[float, float]]#

Get or set the rotation anchor for the camera.

By default, the anchor is the center of the screen and the anchor value is None. Assigning a custom anchor point will override this behavior. The anchor point is in world / global coordinates.

Example:

# Set the anchor to the center of the world
camera.anchor = 0, 0
# Set the anchor to the center of the player
camera.anchor = player.position
move(vector: pyglet.math.Vec2)[source]#

Moves the camera with a speed of 1.0, aka instant move

This is equivalent to calling move_to(my_pos, 1.0)

move_to(vector: pyglet.math.Vec2, speed: float = 1.0)[source]#

Sets the goal position of the camera.

The camera will lerp towards this position based on the provided speed, updating its position every time the use() function is called.

Parameters
  • vector (Vec2) – Vector to move the camera towards.

  • speed (Vec2) – How fast to move the camera, 1.0 is instant, 0.1 moves slowly

resize(viewport_width: int, viewport_height: int)[source]#

Resize the camera’s viewport. Call this when the window resizes.

Parameters
  • viewport_width (int) – Width of the viewport

  • viewport_height (int) – Height of the viewport

property rotation: float#

Get or set the rotation in angles.

This will rotate the camera clockwise meaning the contents will rotate counter-clockwise.

set_projection()[source]#

Update the projection matrix of the camera. This creates an orthogonal projection based on the viewport size of the camera.

shake(velocity: pyglet.math.Vec2, speed: float = 1.5, damping: float = 0.9)[source]#

Add a camera shake.

Parameters
  • velocity (Vec2) – Vector to start moving the camera

  • speed (float) – How fast to shake

  • damping (float) – How fast to stop shaking

update()[source]#

Update the camera’s viewport to the current settings.

use()[source]#

Select this camera for use. Do this right before you draw.

zoom(change: float)[source]#

Zoom the camera in or out. Or not. This will currently raise an error TODO implement