Camera#

class arcade.Camera(*, viewport: Tuple[int, int, int, int] | None = None, projection: Tuple[float, float, float, float] | None = None, zoom: float = 1.0, rotation: float = 0.0, anchor: Tuple[float, float] | None = None, window: Window | None = None)[source]#

Bases: SimpleCamera

The Camera class is used for controlling the visible viewport, the projection, zoom and rotation. 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 – (left, bottom, width, height) size of the viewport. If None the window size will be used.

  • projection – (left, right, bottom, top) size of the projection. If None the window size will be used.

  • zoom – the zoom to apply to the projection

  • rotation – the angle in degrees to rotate the projection

  • anchor – the x, y point where the camera rotation will anchor. Default is the center of the viewport.

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

get_sprites_at_point(point: Point, sprite_list: SpriteList) List['Sprite'][source]#

Get a list of sprites at a particular point when This function sees if any sprite overlaps the specified point. If a sprite has a different center_x/center_y but touches the point, this will return that sprite.

Parameters:
  • point – Point to check

  • sprite_list – SpriteList to check against

Returns:

List of sprites colliding, or an empty list.

set_viewport(viewport: Tuple[int, int, int, int]) None[source]#

Sets the viewport

shake(velocity: Vec2 | tuple, speed: float = 1.5, damping: float = 0.9) None[source]#

Add a camera shake.

Parameters:
  • velocity – Vector to start moving the camera

  • speed – How fast to shake

  • damping – How fast to stop shaking

update() None[source]#

Update the camera’s viewport to the current settings.

use() None[source]#

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

anchor: Tuple[float, float] | None#

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
far: int#

The far applied to the projection

near: int#

The near applied to the projection

rotation: float#

Get or set the rotation in degrees.

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

scale: Tuple[float, float]#

Returns the x, y scale.

zoom: float#

The zoom applied to the projection. Just returns the x scale value.

class arcade.SimpleCamera(*, viewport: Tuple[int, int, int, int] | None = None, projection: Tuple[float, float, float, float] | None = None, window: Window | None = None)[source]#

A simple camera that allows to change the viewport, the projection and can move around. That’s it. See arcade.Camera for more advance stuff.

Parameters:
  • viewport – Size of the viewport: (left, bottom, width, height)

  • projection – Space to allocate in the viewport of the camera (left, right, bottom, top)

center(vector: Vec2 | tuple, speed: float = 1.0) None[source]#

Centers the camera on coordinates

get_map_coordinates(camera_vector: Vec2 | tuple) Vec2[source]#

Returns map coordinates in pixels from screen coordinates based on the camera position

Parameters:

camera_vector – Vector captured from the camera viewport

move(vector: Vec2 | tuple) None[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: Vec2 | tuple, speed: float = 1.0) None[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 – Vector to move the camera towards.

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

resize(viewport_width: int, viewport_height: int, *, resize_projection: bool = True) None[source]#

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

Parameters:
  • viewport_width – Width of the viewport

  • viewport_height – Height of the viewport

  • resize_projection – if True the projection will also be resized

set_viewport(viewport: Tuple[int, int, int, int]) None[source]#

Sets the viewport

update()[source]#

Update the camera’s viewport to the current settings.

use() None[source]#

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

projection: Tuple[float, float, float, float]#

The dimensions of the space to project in the camera viewport (left, right, bottom, top). The projection is what you want to project into the camera viewport.

projection_to_viewport_height_ratio#

The ratio of projection height to viewport height

projection_to_viewport_width_ratio#

The ratio of projection width to viewport width

viewport: Tuple[int, int, int, int]#

The space the camera will hold on the screen (left, bottom, width, height)

viewport_height: int#

Returns the height of the viewport

viewport_to_projection_height_ratio#

The ratio of viewport height to projection height

viewport_to_projection_width_ratio#

The ratio of viewport width to projection width

viewport_width: int#

Returns the width of the viewport