Camera#

arcade.Camera#

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

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 (tuple) – (left, bottom, width, height) size of the viewport. If None the window size will be used.

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

  • zoom (float) – the zoom to apply to the projection

  • rotation (float) – the angle in degrees to rotate the projection

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

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

The far applied to the projection

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) – Point to check

  • sprite_list (SpriteList) – SpriteList to check against

Returns:

List of sprites colliding, or an empty list.

Return type:

list

property near: int#

The near applied to the projection

property rotation: float#

Get or set the rotation in degrees.

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

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

Sets the viewport

shake(velocity: Union[Vec2, tuple], speed: float = 1.5, damping: float = 0.9) None[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() 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.

arcade.SimpleCamera#

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

A simple camera that allows to change the viewport, the projection, the zoom 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: Union[Vec2, tuple], speed: float = 1.0) None[source]#

Centers the camera on coordinates

get_map_coordinates(camera_vector: Union[Vec2, tuple]) Vec2[source]#

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

Parameters:

camera_vector (Vec2) – Vector captured from the camera viewport

move(vector: Union[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: Union[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 (Vec2) – Vector to move the camera towards.

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

property 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.

property projection_to_viewport_height_ratio#

The ratio of viewport height to projection height

property projection_to_viewport_width_ratio#

The ratio of viewport width to projection width

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 (int) – Width of the viewport

  • viewport_height (int) – Height of the viewport

  • resize_projection (bool) – if True the projection will also be resized

property scale: Tuple[float, float]#

Returns the x, y scale from the difference of projection to view.

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.

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

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

property viewport_height: int#

Returns the height of the viewport

property viewport_to_projection_height_ratio#

The ratio of viewport height to projection height

property viewport_to_projection_width_ratio#

The ratio of viewport width to projection width

property viewport_width: int#

Returns the width of the viewport

property zoom: float#

The zoom applied to the projection based on the width scale