simvx.core.nodes_2d.camera

Camera2D – 2D camera with smoothing, zoom, bounds, and shake.

Module Contents

Classes

Camera2D

2D camera for scrolling games.

API

class simvx.core.nodes_2d.camera.Camera2D(**kwargs)[source]

Bases: simvx.core.nodes_2d.node2d.Node2D

2D camera for scrolling games.

Provides target following with smoothing, zoom, viewport bounds/limits, and screen shake effects. The active Camera2D’s offset is applied by the renderer to all 2D draw calls.

Initialization

zoom

‘Property(…)’

smoothing

‘Property(…)’

limit_left

‘Property(…)’

limit_right

‘Property(…)’

limit_top

‘Property(…)’

limit_bottom

‘Property(…)’

cull_mask

‘Bitmask(…)’

gizmo_colour

‘Colour(…)’

set_cull_mask_layer(index: int, enabled: bool = True) None[source]

Enable or disable a specific cull mask layer (0-31).

is_cull_mask_layer_enabled(index: int) bool[source]

Check if a specific cull mask layer is enabled (0-31).

property current: simvx.core.math.types.Vec2[source]

Current smoothed camera position in world space.

Reads the post-smoothing, post-limit-clamp position the renderer uses to translate 2D draws. Assignment teleports the camera (skips smoothing for that frame): equivalent to :meth:snap_to without rebinding to the target’s world_position.

on_ready()[source]
on_exit_tree() None[source]

Clear the tree’s current-camera reference if it points at us.

Without this, destroying the active Camera2D leaves a stale reference on the tree: the renderer keeps following the freed camera each frame, panning over to whatever world_position arrives via stale _current. Other Camera2D instances claim the slot back via their own on_ready(); the only failure mode is “active camera was the last one in the scene”, which now correctly resets to None.

shake(intensity: float = 5.0, duration: float = 0.3)[source]

Start a screen shake effect.

snap_to(pos: simvx.core.math.types.Vec2 | None = None) None[source]

Skip smoothing this frame.

If pos is given, snap there. If pos is None, snap to the current target’s world_position (or the camera’s own world_position if no target). Bounds limits and zoom are honoured; shake jitter continues uninterrupted.

on_process(dt: float)[source]
world_to_screen(world_pos: simvx.core.math.types.Vec2, screen_size: simvx.core.math.types.Vec2) simvx.core.math.types.Vec2[source]

Convert a world position to screen coordinates.

screen_to_world(screen_pos: simvx.core.math.types.Vec2, screen_size: simvx.core.math.types.Vec2) simvx.core.math.types.Vec2[source]

Convert screen coordinates to world position.

get_gizmo_lines() list[tuple[simvx.core.math.types.Vec2, simvx.core.math.types.Vec2]][source]

Return line segments for viewport bounds rectangle and crosshair at camera position.

position

‘_SpatialVecProperty(…)’

rotation

‘Property(…)’

scale

‘_SpatialVecProperty(…)’

z_index

‘Property(…)’

z_as_relative

‘Property(…)’

render_layer

‘Property(…)’

set_render_layer(index: int, enabled: bool = True) None
is_on_render_layer(index: int) bool
property absolute_z_index: int
property rotation_degrees: float
property world_position: simvx.core.math.types.Vec2
property world_rotation: float
property world_scale: simvx.core.math.types.Vec2
property world_transform: tuple[simvx.core.math.types.Vec2, simvx.core.math.types.Vec2, float]
property forward: simvx.core.math.types.Vec2
property right: simvx.core.math.types.Vec2
translate(offset: tuple[float, float] | numpy.ndarray)
rotate(radians: float)
rotate_deg(degrees: float)
look_at(target: tuple[float, float] | numpy.ndarray)
transform_points(points: list[simvx.core.math.types.Vec2]) list[simvx.core.math.types.Vec2]
draw_polygon(renderer, points: list[simvx.core.math.types.Vec2], closed=True, colour=None)
wrap_screen(margin: float = 20)
strict_errors: ClassVar[bool]

True

script_error_raised

‘Signal(…)’

classmethod __init_subclass__(**kwargs)
property name: str
property process_mode: simvx.core.descriptors.ProcessMode
property visible: bool
reset_error() None
add_child(node: simvx.core.node.Node) simvx.core.node.Node
remove_child(node: simvx.core.node.Node)
reparent(new_parent: simvx.core.node.Node)
get_node(path: str) simvx.core.node.Node
find_child(name: str, recursive: bool = False) simvx.core.node.Node | None
find(target: type | str, recursive: bool = True) simvx.core.node.Node | None
find_all(node_type: type, recursive: bool = True) list
walk(*, include_self: bool = True) collections.abc.Iterator[simvx.core.node.Node]
property path: str
add_to_group(group: str)
remove_from_group(group: str)
is_in_group(group: str) bool
on_enter_tree() None
on_physics_process(dt: float) None
on_draw(renderer) None
on_picked(event: simvx.core.events.InputEvent) None
on_unhandled_input(event: simvx.core.events.TreeInputEvent) None
start_coroutine(gen: simvx.core.descriptors.Coroutine) simvx.core.descriptors.CoroutineHandle
stop_coroutine(gen_or_handle)
clear_children()
destroy()
property app
property tree: simvx.core.scene_tree.SceneTree
__getitem__(key: str)
classmethod get_properties() dict[str, simvx.core.descriptors.Property]
__repr__()