goopylib.scene
- class Camera(left: float, right: float, bottom: float, top: float)
An orthographic camera associated with a Window.
- Parameters
left (
float
) – left clipping planeright (
float
) – right clipping planebottom (
float
) – bottom clipping planetop (
float
) – top clipping plane
- Raises
TypeError – arguments must be numbers
- set_projection(left: float, right: float, bottom: float, top: float) None
Sets an orthographic projection for the camera
- Parameters
left (
float
) – left clipping planeright (
float
) – right clipping planebottom (
float
) – bottom clipping planetop (
float
) – top clipping plane
- Raises
TypeError – arguments must be numbers
- Return type
None
- move(dx: float, dy: float) None
Moves (translate) the camera’s position
- Parameters
dx (
float
) – change in x positiondy (
float
) – change in y position
- Raises
TypeError – arguments must be numbers
- Return type
None
- rotate(angle: float) None
Rotates the camera
- Parameters
angle (
float
) – in degrees- Raises
TypeError – angle must be a number
- Return type
None
- zoomin(value: float) None
Zooms the camera in. A value less than 1 zooms the camera out.
- Parameters
value (
float
) – zoom amount- Raises
TypeError – zoom must be a number
- Return type
None
- property x: float
The x-position of the camera
- Raises
TypeError – value must be a number
- Return type
float
- property y: float
The y-position of the camera
- Raises
TypeError – value must be a number
- Return type
float
- property position: float
The position of the camera as an
(x, y)
tuple- Raises
TypeError – value must be a tuple of numbers
- Return type
float
- property rotation: float
The rotation of the camera in degrees
- Raises
TypeError – value must be a number
- Return type
float
- property zoom: float
The zoom amount of the camera in %
- Raises
TypeError – value must be a number
- Return type
float
Camera Controller
- class CameraController(window: Window)
Controller class that automatically manages camera movement, rotation, and zoom.
This is a helper class that wraps around a Window’s camera and provides basic but quick functionality
- Parameters
window (
Window
) – the window to use
- Raises
TypeError: window must be a goopylib Window
- update() None
Updates the controller. Call this method in the mainloop.
- Return type
None
- enable_movement(value: bool) None
Enables automatic camera movement when the control keys are pressed.
- Parameters
value (
bool
) – whether to enable or disable movement- Raises
TypeError – value must be a boolean
- Return type
None
- enable_rotation(value: bool) None
Enables automatic camera rotation when the control keys are pressed.
- Parameters
value (
bool
) – whether to enable or disable rotation- Raises
TypeError – value must be a boolean
- Return type
None
- enable_zoom(value: bool) None
Enables automatic camera zooming when the control keys are pressed.
- Parameters
value (
bool
) – whether to enable or disable zooming- Raises
TypeError – value must be a boolean
- Return type
None
- invert_movement(value: bool) None
Inverts camera movement.
- Parameters
value (
bool
) – whether to invert the movement- Raises
TypeError – value must be a boolean
- Return type
None
- invert_rotation(value: bool) None
Inverts camera rotation.
- Parameters
value (
bool
) – whether to invert the rotation- Raises
TypeError – value must be a boolean
- Return type
None
- property horizontal_speed: float
The horizontal movement speed of the camera.
- Returns
float
– the horizontal movement speed- Raises
TypeError – speed must be a number
- property vertical_speed: float
The vertical movement speed of the camera.
- Returns
float
– the vertical movement speed- Raises
TypeError – speed must be a number
- property rotate_speed: float
The rotational speed of the camera.
- Returns
float
– the rotation speed- Raises
TypeError – speed must be a number
- property zoom_speed: float
The zoom speed of the camera.
- Returns
float
– the zoom speed- Raises
TypeError – speed must be a number
- use_wasd() None
Binds the WASD keys for camera movement.
- Return type
None
- use_arrows() None
Binds the arrow keys for camera movement.
- Return type
None
- set_movement_keys(up: int, left: int, down: int, right: int) None
Sets the keys used for camera movement.
- Parameters
up (
int
) – key to use for moving upleft (
int
) – key to use for moving leftdown (
int
) – key to use for moving downright (
int
) – key to use for moving right
- Raises
TypeError – arguments must be keys
- Return type
None
- set_rotation_keys(clockwise: int, anticlockwise: int) None
Sets the keys used for camera rotation.
- Parameters
clockwise (
int
) – key to use for clockwise rotationanticlockwise (
int
) – key to use for anticlockwise rotation
- Raises
TypeError – arguments must be keys
- Return type
None
- set_zoom_keys(zoomin: int, zoomout: int) None
Sets the keys used for camera zooming.
- Parameters
zoomin (
int
) – key to use for zooming inzoomout (
int
) – key to use for zooming out
- Raises
TypeError – arguments must be keys
- Return type
None