gale.physics.node module

This file contains the implementation of the class Node: a lightweight scene graph node for organizing physics entities, optionally driven by a Body (whose position/angle then take over as the source of truth), with children for grouping/attachment.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.physics.node.Node(x=0, y=0, body=None, children=None)[source]

Bases: object

A lightweight scene graph node for organizing physics entities: every node has an absolute position (matching how everything else in gale already works), optionally owns a Body (in which case its position/angle are pulled from the body every update, since physics is the source of truth for anything simulated), and can have children for grouping/attachment — a decorative or dependent node that should follow its parent’s body around, or just a way to destroy a group of related nodes together.

This mirrors gale.ui.Container’s parent/children/add_order-render pattern, applied to physics entities instead of widgets.

Usage example:

chassis_node = Node(body=chassis_body) exhaust_node = Node(offset=(-20, 0)) # a decoration, no body of its own chassis_node.add_child(exhaust_node)

# Every frame, after world.update(dt): chassis_node.update(dt) chassis_node.render(surface)

Parameters:
  • x (float)

  • y (float)

  • body (Body | None)

  • children (Sequence[Node] | None)

add_child(node)[source]
Parameters:

node (Node) – The child to add. Rendered/updated after every previously added child (add-order is z-order, as in gale.ui.Container).

Return type:

None

remove_child(node)[source]
Parameters:

node (Node) – The child to remove.

Return type:

None

property world_position: Vector2

This node’s absolute position. A node with a body already has an absolute position (Box2D bodies are always in world coordinates); otherwise, this composes every ancestor’s position with this node’s own offset.

Type:

returns

update(dt)[source]
Parameters:

dt (float) – Time elapsed, in seconds, since the last call.

Return type:

None

render(surface)[source]
Parameters:

surface (Surface) – The surface to draw this node (and its children) on. The base Node itself draws nothing — subclasses/games draw whatever they want at self.world_position.

Return type:

None