World > Camera#

Neben Scrollen und Koordinatenumrechnung bietet world.camera auch die öffentlichen Hilfsmethoden add_right(...), add_bottom(...), remove_world(...) und switch_world(...).

API Reference#

class miniworlds.worlds.manager.camera_manager.CameraManager(view_x, view_y, world)[Quellcode]#

Der CameraManager definiert einen beweglichen Ausschnitt einer 2D-Welt und verfolgt sichtbare Actors. Er ist ueber world.camera erreichbar und fuer Blickfeldposition, Sichtbarkeit von Actors und Koordinatenumrechnungen zustaendig.

For public API compatibility, docking and world-switching helpers are also exposed through world.camera and delegated internally to the layout manager.

add_bottom(world, size=100)[Quellcode]#

Dock a helper world below the current world.

Rückgabetyp:

World

add_right(world, size=100)[Quellcode]#

Dock a helper world to the right side of the current world.

Rückgabetyp:

World

property center: Tuple[float, float]#

Returns center of camera in world coordinates.

from_actor(actor)[Quellcode]#

Move camera to center on a given actor.

Rückgabetyp:

None

Examples

>>> world.camera.from_actor(actor)
get_actors_in_view()[Quellcode]#
Rückgabetyp:

Set[Actor]

get_global_coordinates_for_world(pos)[Quellcode]#

Convert local camera position to global world position.

Rückgabetyp:

Optional[Tuple[int, int]]

Parameter:

pos – Position relative to the camera, or None if no position is available.

Rückgabe:

Global world position, or None if pos is None.

Examples

>>> world.camera.get_global_coordinates_for_world((100, 50))
get_local_position(pos)[Quellcode]#

Convert world coordinates to camera-local coordinates.

Rückgabetyp:

Tuple[int, int]

Parameter:

pos – Global position in the world.

Rückgabe:

Local position relative to the camera.

Examples

>>> world.camera.get_local_position((500, 400))
get_rect()[Quellcode]#

Returns the camera rectangle in world coordinates.

Rückgabetyp:

Rect

Rückgabe:

A pygame.Rect representing the current viewport’s world area.

Examples

>>> world.camera.get_rect()
get_screen_position(pos)[Quellcode]#

Convert world coordinates to screen coordinates.

Rückgabetyp:

Tuple[int, int]

Parameter:

pos – Position in world coordinates.

Rückgabe:

Position in screen coordinates.

Examples

>>> world.camera.get_screen_position((100, 200))
get_screen_rect()[Quellcode]#

Returns the camera rectangle in screen coordinates.

Rückgabetyp:

Rect

Rückgabe:

A pygame.Rect representing where the camera appears on screen.

Examples

>>> world.camera.get_screen_rect()
get_world_rect()[Quellcode]#

Returns the full world rectangle from the camera’s current origin.

Rückgabetyp:

Rect

Rückgabe:

A pygame.Rect representing the visible and scrolled world area.

Examples

>>> world.camera.get_world_rect()
property height: int#

Height of the camera viewport in pixels.

is_actor_in_view(actor)[Quellcode]#
Rückgabetyp:

bool

is_in_screen(pixel)[Quellcode]#
Rückgabetyp:

bool

remove_world(world)[Quellcode]#

Remove a previously docked world.

Rückgabetyp:

None

property screen_rect: Rect#

Returns camera rect in screen coordinates.

switch_world(new_world, reset=False)[Quellcode]#

Switch to another world through the public camera API.

Rückgabetyp:

None

property topleft: Tuple[int, int]#

Top-left corner of the camera in world coordinates.

property width: int#

Width of the camera viewport in pixels.

property window_docking_position: str | None#

Returns the docking position of this world in the application window.

property world_rect: Rect#

Returns the full world rect.

property world_size: Tuple[int, int]#

Returns world size as (width, height).

property world_size_x: int#

Width of the world in pixels.

property world_size_y: int#

Height of the world in pixels.

property x: int#

Camera x-position (top-left corner in world coordinates).

property y: int#

Camera y-position (top-left corner in world coordinates).