Camera#
arcade.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]#
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: 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
- 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:
- property rotation: float#
Get or set the rotation in degrees.
This will rotate the camera clockwise meaning the contents will rotate counter-clockwise.
arcade.SimpleCamera#
- 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)
- 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 (Vec2) – 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 (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 projection height to viewport height
- property projection_to_viewport_width_ratio#
The ratio of projection width to viewport 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.
- property viewport: Tuple[int, int, int, int]#
The space the camera will hold on the screen (left, bottom, width, height)
- 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