Animation¶
SimVX provides four animation systems, from simple to complex.
Tweens¶
Animate any property over time with easing:
from simvx.core import tween
from simvx.core.animation import ease_out_quad
# Basic tween (runs as a coroutine)
self.start_coroutine(
tween(self, "position", Vec3(10, 0, 0), duration=1.0, easing=ease_out_quad)
)
# With callbacks and repeat
yield from tween(
node, "rotation", Quat.from_euler(0, 360, 0),
duration=2.0,
delay=0.5,
repeat=3,
on_complete=lambda: print("Done!"),
)
Tween Chains¶
Chain sequential animations fluently:
from simvx.core.animation import TweenChain, ease_in_out_quad
TweenChain(obj, "position", Vec3(0, 0, 0)) \
.to(Vec3(10, 0, 0), 1.0, ease_in_out_quad) \
.wait(0.5) \
.to(Vec3(0, 0, 0), 1.0) \
.on_complete(lambda: print("Loop!")) \
.build()
Easing Functions¶
30 built-in easing curves:
Family |
In |
Out |
In-Out |
|---|---|---|---|
Linear |
|
||
Quad |
|
|
|
Cubic |
|
|
|
Quart |
|
|
|
Quint |
|
|
|
Sine |
|
|
|
Expo |
|
|
|
Back |
|
|
|
Elastic |
|
|
|
Bounce |
|
|
|
Sprite Sheet Animation¶
For 2D frame-based animations:
from simvx.core import AnimatedSprite2D
sprite = AnimatedSprite2D(
texture="player.png",
frames_horizontal=4,
frames_vertical=4,
)
sprite.add_animation("walk", frames=[0, 1, 2, 3], fps=10, loop=True)
sprite.add_animation("jump", frames=[4, 5, 6], fps=15, loop=False)
sprite.play("walk")
Keyframe Clips¶
Timeline-based animation with multiple property tracks:
from simvx.core import AnimationClip, AnimationPlayer
clip = AnimationClip("jump", duration=1.0)
clip.add_track("position", [
(0.0, Vec3(0, 0, 0)),
(0.5, Vec3(0, 5, 0)),
(1.0, Vec3(0, 0, 0)),
])
player = AnimationPlayer(target=my_node)
player.add_clip(clip)
player.play("jump", loop=True)
Animation State Machine¶
Transition between animations based on conditions:
from simvx.core import AnimationTree
tree = AnimationTree(target=character)
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.set_parameter("speed", 0.0)
tree.start("idle")
API Reference¶
See simvx.core.animation for the complete animation API.