simvx.core.animation.state_machine

Animation state machine with parameter-based transitions.

Module Contents

Classes

AnimationState

Single state in animation state machine.

Transition

Transition between animation states.

AnimationTree

Animation state machine with parameter-based transitions.

Data

log

API

simvx.core.animation.state_machine.log

‘getLogger(…)’

class simvx.core.animation.state_machine.AnimationState[source]

Single state in animation state machine.

name: str

None

clip: simvx.core.animation.track.AnimationClip

None

speed_scale: float

1.0

loop: bool

True

class simvx.core.animation.state_machine.Transition[source]

Transition between animation states.

from_state: str

None

to_state: str

None

condition: collections.abc.Callable[[], bool]

None

blend_time: float

0.2

class simvx.core.animation.state_machine.AnimationTree(**kwargs)[source]

Bases: simvx.core.node.Node

Animation state machine with parameter-based transitions.

As a Node subclass, it participates in the scene tree and gets on_update(dt) called automatically. By default it animates its parent.

Properties: target: The node whose properties are animated. Defaults to parent when it is left unset.

Attributes: states: Registered AnimationState objects keyed by name. Each holds an AnimationClip, which has no source form, so a saved scene does not carry the states and they are rebuilt by the code that added them. transitions: Registered Transition objects. Each holds a Callable condition, so these are not carried by a save either. parameters: The gameplay values transition conditions read, written through :meth:set_parameter. Runtime state. current_state, current_time, playing: Playback state. blending, blend_from, blend_to, blend_time, blend_duration: Transition state. blend_duration is the length of the crossfade now in flight, copied from the blend_time the transition declared, so it says nothing about a tree that is not mid-transition.

Example: tree = AnimationTree(target=player) tree.add_state(“idle”, idle_clip, loop=True) tree.add_state(“run”, run_clip, loop=True) tree.add_state(“jump”, jump_clip, loop=False)

tree.add_transition("idle", "run", lambda: tree.parameters["speed"] > 0.1)
tree.add_transition("run", "idle", lambda: tree.parameters["speed"] < 0.1)
tree.add_transition("idle", "jump", lambda: tree.parameters["jump_pressed"])

tree.set_parameter("speed", 0.0)
tree.start("idle")

Initialization

target

‘Property(…)’

__transient__

‘frozenset(…)’

add_state(name: str, clip: simvx.core.animation.track.AnimationClip, speed_scale: float = 1.0, loop: bool = True)[source]

Add animation state.

add_transition(from_state: str, to_state: str, condition: collections.abc.Callable[[], bool], blend_time: float = 0.2)[source]

Add transition with condition function.

set_parameter(name: str, value: Any)[source]

Update animation parameter.

get_parameter(name: str, default: Any = None) → Any[source]

Get animation parameter.

start(state_name: str)[source]

Start animation tree with initial state.

Raises: KeyError: no state was added under state_name.

stop()[source]

Stop animation tree.

on_update(dt: float)[source]

Advance animation state machine each frame (called by SceneTree).

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_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__()