World > Camera#
Besides scrolling and coordinate conversion, world.camera also offers
the public helper methods add_right(...), add_bottom(...),
remove_world(...), and switch_world(...).
API Reference#
- class miniworlds.worlds.manager.camera_manager.CameraManager(view_x, view_y, world)[source]#
CameraManager defines a movable viewport into a 2D world and tracks visible actors. It is accessed via world.camera and is responsible for view positioning, actor visibility, and coordinate transformations.
For public API compatibility, docking and world-switching helpers are also exposed through world.camera and delegated internally to the layout manager.
- add_right(world, size=100)[source]#
Dock a helper world to the right side of the current world.
- Return type:
- from_actor(actor)[source]#
Move camera to center on a given actor.
- Return type:
Examples
>>> world.camera.from_actor(actor)
- get_global_coordinates_for_world(pos)[source]#
Convert local camera position to global world position.
- Return type:
- Parameters:
pos – Position relative to the camera, or None if no position is available.
- Returns:
Global world position, or None if pos is None.
Examples
>>> world.camera.get_global_coordinates_for_world((100, 50))
- get_local_position(pos)[source]#
Convert world coordinates to camera-local coordinates.
- Return type:
- Parameters:
pos – Global position in the world.
- Returns:
Local position relative to the camera.
Examples
>>> world.camera.get_local_position((500, 400))
- get_rect()[source]#
Returns the camera rectangle in world coordinates.
- Return type:
Rect- Returns:
A pygame.Rect representing the current viewport’s world area.
Examples
>>> world.camera.get_rect()
- get_screen_position(pos)[source]#
Convert world coordinates to screen coordinates.
- Return type:
- Parameters:
pos – Position in world coordinates.
- Returns:
Position in screen coordinates.
Examples
>>> world.camera.get_screen_position((100, 200))
- get_screen_rect()[source]#
Returns the camera rectangle in screen coordinates.
- Return type:
Rect- Returns:
A pygame.Rect representing where the camera appears on screen.
Examples
>>> world.camera.get_screen_rect()
- get_world_rect()[source]#
Returns the full world rectangle from the camera’s current origin.
- Return type:
Rect- Returns:
A pygame.Rect representing the visible and scrolled world area.
Examples
>>> world.camera.get_world_rect()
- property screen_rect: Rect#
Returns camera rect in screen coordinates.
- switch_world(new_world, reset=False)[source]#
Switch to another world through the public camera API.
- Return type:
- 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.