Skip to content

node

FreeBodyEngine.core.node #

GenericNode() #

Base class of the Node Tree Node.

Builds inheritance_hierarchy (the class's MRO, base-first, as class name strings) up front so inherits_from can do plain string lookups instead of walking the MRO on every call.

children = {} instance-attribute #

id = 0 instance-attribute #

inheritance_hierarchy = [(cls.__name__) for cls in (self.__class__.__mro__) if cls != object] instance-attribute #

is_initialized = False instance-attribute #

scene instance-attribute #

add(*nodes) #

Adds any amount of nodes to the given nodes children.

find_nodes_with_type(type) #

Recursively collects every node in this subtree (self included) whose inheritance_hierarchy contains type.

get_tree_dict() #

Create a dictionary with this node's info and its children list.

inherits_from(*type) #

Returns whether this node's class or any of its base classes matches one of the given class name(s).

kill() #

Removes this node from the tree. No-op by default - Node overrides this to actually detach from its parent.

log_tree() #

Logs a node tree in human-readable tree format.

on_update() #

Called every frame during update; override to add per-frame behavior. No-op by default.

remove(*ids) #

Removes the children with the given ids.

update() #

Runs on_update on this node, then recursively updates every child.

Node() #

Bases: GenericNode

The Node class.

A freshly-constructed Node is not yet part of the tree - is_initialized stays False, and scene/parent are unset, until it's added to another node via add() and _initialize() runs.

id = uuid.uuid4() instance-attribute #

is_initialized = False instance-attribute #

parent instance-attribute #

parental_requirement = 'Node' instance-attribute #

requirements = [] instance-attribute #

kill() #

Removes the node from its parent.

on_draw() #

Hook meant for custom per-node draw logic (overridden by e.g. Sprite2D), but not currently called by the tree traversal or the renderer - rendering instead goes through find_nodes_with_type elsewhere. No-op by default.

on_event_loop(event) #

Hook meant for handling input/window events; not currently invoked by anything in the engine. No-op by default.

on_initialize() #

Called once this node has been attached to its parent and self.scene/self.parent are set; override to add setup logic that depends on the tree. No-op by default.

on_kill() #

Called after this node has been removed from its parent by kill; override to add teardown logic. No-op by default.

on_post_update() #

Hook meant to run once every node's update has finished for the frame; not currently invoked by anything in the engine. No-op by default.

on_pre_update() #

Hook meant to run before any node's update runs for the frame; not currently invoked by anything in the engine. No-op by default.

on_update() #

Called every frame during update; override to add per-frame behavior. No-op by default.

Node2D(position=Vector(), rotation=0.0, scale=Vector(1, 1)) #

Bases: Node

A Node with a 2D Transform, requiring a Node2D (or root) parent so world_transform can compose up the tree.

Sets parental_requirement to "Node2D", so _initialize warns if this node ends up under a non-Node2D parent.

parental_requirement = 'Node2D' instance-attribute #

transform = Transform(position, rotation, scale) instance-attribute #

world_position property #

Shorthand for self.world_transform.position.

world_rotation property #

Shorthand for self.world_transform.rotation.

world_transform property #

This node's transform composed with its ancestors', giving its transform in world space rather than parent-local space. Falls back to the local transform unchanged if the parent isn't a Node2D (e.g. it's the scene's RootNode).

Node3D(position=Vector3(), rotation=Vector3(), scale=Vector3(1, 1, 1)) #

Bases: Node

A Node with a 3D Transform3, requiring a Node3D (or root) parent so world_transform can compose up the tree.

Sets parental_requirement to "Node3D", so _initialize warns if this node ends up under a non-Node3D parent.

parental_requirement = 'Node3D' instance-attribute #

transform = Transform3(position, rotation, scale) instance-attribute #

world_transform property #

This node's transform composed with its ancestors', giving its transform in world space rather than parent-local space. Falls back to the local transform unchanged if the parent isn't a Node3D (e.g. it's the scene's RootNode).

RootNode(scene) #

Bases: GenericNode

A root node object.

A root node is considered initialized as soon as it's built, unlike a regular Node which only initializes once attached to a parent - a root has no parent to attach to.

is_initialized = True instance-attribute #

scene = scene instance-attribute #

kill() #

Refuses to kill the root node, logging a warning instead.