simvx.core.nodes_2d.node2d

Node2D – 2D spatial node with position, rotation, and scale.

Module Contents

Classes

Node2D

2D spatial node with position, rotation, and scale.

API

class simvx.core.nodes_2d.node2d.Node2D(**kwargs)[source]

Bases: simvx.core._drawable2d.Drawable2D, simvx.core.node.Node

2D spatial node with position, rotation, and scale.

Extends Node with a 2D transform (position, rotation, scale) and cached world-transform propagation. All spatial 2D nodes – sprites, cameras, collision shapes – inherit from this.

Attributes: position: Local position as Vec2 (pixels). rotation: Local rotation in radians (float). scale: Local scale as Vec2 (default (1, 1)). z_index: Draw order relative to siblings (higher = on top). z_as_relative: When True (default), z_index is added to the parent’s absolute z-index.

Example::

player = Node2D(position=(100, 200), rotation=0.0, name="Player")
player.position += Vec2(10, 0)
print(player.world_position)

Initialization

position

‘_SpatialVecProperty(…)’

rotation

‘Property(…)’

scale

‘_SpatialVecProperty(…)’

top_level

‘Property(…)’

z_index

‘Property(…)’

z_as_relative

‘Property(…)’

render_layer

‘Property(…)’

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

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

is_on_render_layer(index: int) → bool[source]

Check if this node is on a specific render layer (0-31).

property absolute_z_index: int[source]

Compute absolute z-index walking up the tree (cached).

property rotation_degrees: float[source]

Local rotation in degrees (convenience for editor display).

property world_position: simvx.core.math.types.Vec2[source]
property world_rotation: float[source]

World rotation in radians.

property world_scale: simvx.core.math.types.Vec2[source]
property world_transform: tuple[simvx.core.math.types.Vec2, simvx.core.math.types.Vec2, float][source]

All three world-transform components in one call: (world_position, world_scale, world_rotation).

Hot-path callers (sprite on_draw, scene-adapter walks, anything that today reads the three component properties back-to-back) should prefer this: it pays the dirty-flag check + cache materialisation exactly once instead of three times.

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

Unit vector pointing in the direction of rotation (up = -Y in screen coords).

property right: simvx.core.math.types.Vec2[source]
translate(offset: tuple[float, float] | numpy.ndarray)[source]
rotate(radians: float)[source]

Rotate by the given number of radians.

rotate_deg(degrees: float)[source]

Rotate by the given number of degrees.

look_at(target: tuple[float, float] | numpy.ndarray)[source]
to_global(point) → simvx.core.math.types.Vec2[source]

A point in this node’s local space, in world (canvas) space.

to_local(point) → simvx.core.math.types.Vec2[source]

A world (canvas) point in this node’s local space: the inverse of :meth:to_global.

Raises: ValueError: the node is scaled to zero on an axis, so it has no local space.

transform_points(points: list[simvx.core.math.types.Vec2]) → list[simvx.core.math.types.Vec2][source]

Transform local points into WORLD space (scale, then rotate, then translate).

wrap_screen(margin: float = 20)[source]

Wrap position around screen edges.

post_processed

‘Property(…)’

property transform_render_dirty: bool
strict_errors: ClassVar[bool]

True

dev_checks: ClassVar[bool]

None

dev_warnings: ClassVar[bool]

None

freeze_check_interval: ClassVar[float]

1.0

dynamic: bool

False

visible

‘Property(…)’

update_mode

‘Property(…)’

focus_mode

‘Property(…)’

drag_threshold

‘Property(…)’

focus_entered

‘Signal(…)’

focus_exited

‘Signal(…)’

__properties__: ClassVar[dict[str, simvx.core.descriptors.Property]]

None

classmethod __init_subclass__(**kwargs)
property name: str
property visible_in_tree: bool
property input_player: simvx.core.input.players.InputPlayer
property input_context: simvx.core.input.contexts.InputContext | None
reset_error() → None
add_child(node: simvx.core.node.T) → simvx.core.node.T
remove_child(node: simvx.core.node.Node) → None
reparent(new_parent: simvx.core.node.Node)
node_at(path, default=_NO_DEFAULT)
find(target, *, direct: bool = False)
find_all(target, *, direct: bool = False)
expect(target, *, direct: bool = False)
ancestor(target)
walk(*, include_self: bool = True) → collections.abc.Iterator[simvx.core.node.Node]
property path: str
property is_scene_root: bool
add_to_group(group: str)
remove_from_group(group: str)
is_in_group(group: str) → bool
on_ready() → None
on_enter_tree() → None
on_exit_tree() → None
on_update(dt: float) → None
on_fixed_update(dt: float) → None
on_draw(canvas) → None
on_draw_3d(gizmos) → None
on_picked(event: simvx.core.input.events.PickEvent) → bool | None
on_gui_input(event: simvx.core.input.events.GuiInputEvent) → bool | None
start_coroutine(gen: simvx.core.descriptors.Coroutine) → simvx.core.descriptors.CoroutineHandle
stop_coroutine(gen_or_handle)
property focused: bool
property focus_rect: tuple[float, float, float, float] | None
drag_threshold_for(pointer_type: simvx.core.input.enums.PointerType | str) → float
grab_focus() → None
release_focus() → None
capture_pointer(pointer_id: int | None = None) → None
release_pointer(pointer_id: int | None = None) → None
queue_redraw() → None
property render_dirty: bool
clear_children()
destroy()
property destroying: bool
property destroyed: bool
call_deferred(method: collections.abc.Callable[..., Any], *args: Any) → None
property app
property tree: simvx.core.scene_tree.SceneTree
property viewport_size: simvx.core.math.types.Vec2
property viewport_insets: tuple[float, float, float, float]
property physics
property physics_2d
__getitem__(key: str)
classmethod get_properties() → dict[str, simvx.core.descriptors.Property]
__repr__()