simvx.core.animation.tween¶
Tween system and easing functions for property animation.
Tweens are time-based: each yield returns the per-tick dt (in
seconds) sent by the coroutine driver, which the tween accumulates as
elapsed time. There is no notion of “frames” inside a tween: duration
is honoured regardless of frame rate.
Module Contents¶
Classes¶
Chainable tween builder for sequential animations. |
|
Namespace for one-liner tween shorthands. |
Functions¶
Linear interpolation (no easing). |
|
Quadratic ease-in. |
|
Quadratic ease-out. |
|
Quadratic ease-in-out. |
|
Cubic ease-in. |
|
Cubic ease-out. |
|
Cubic ease-in-out. |
|
Quartic ease-in. |
|
Quartic ease-out. |
|
Quartic ease-in-out. |
|
Quintic ease-in. |
|
Quintic ease-out. |
|
Quintic ease-in-out. |
|
Sine ease-in. |
|
Sine ease-out. |
|
Sine ease-in-out. |
|
Exponential ease-in. |
|
Exponential ease-out. |
|
Exponential ease-in-out. |
|
Back ease-in (overshoots). |
|
Back ease-out (overshoots). |
|
Back ease-in-out (overshoots). |
|
Elastic ease-in (spring effect). |
|
Elastic ease-out (spring effect). |
|
Elastic ease-in-out (spring effect). |
|
Bounce ease-in. |
|
Bounce ease-out. |
|
Bounce ease-in-out. |
|
Resolve a registered easing function by name. |
|
Return the canonical registered name for an easing function. |
|
Time-based property tween generator with callbacks and repeating. |
Data¶
API¶
- simvx.core.animation.tween.log¶
‘getLogger(…)’
- simvx.core.animation.tween.ease_in_elastic(t: float) float[source]¶
Elastic ease-in (spring effect).
- simvx.core.animation.tween.ease_out_elastic(t: float) float[source]¶
Elastic ease-out (spring effect).
- simvx.core.animation.tween.ease_in_out_elastic(t: float) float[source]¶
Elastic ease-in-out (spring effect).
- simvx.core.animation.tween.EASING_FUNCTIONS: dict[str, collections.abc.Callable[[float], float]]¶
None
- simvx.core.animation.tween.easing_by_name(name: str) collections.abc.Callable[[float], float][source]¶
Resolve a registered easing function by name.
Falls back to :func:
ease_linear(with a warning) for unknown names, so a forward-compatible save written with a newer easing never fails to load.
- simvx.core.animation.tween.easing_name(fn: collections.abc.Callable[[float], float]) str[source]¶
Return the canonical registered name for an easing function.
Registered functions resolve directly. An unregistered callable (e.g. a user-supplied lambda) is matched by
__name__if that name happens to be registered; otherwise it is recorded as"ease_linear"with a warning, since an anonymous function cannot be round-tripped by name.
- class simvx.core.animation.tween.TweenChain(obj, prop: str, start_value=None)[source]¶
Chainable tween builder for sequential animations.
Example: TweenChain(obj, ‘position’, Vec3(0, 0, 0))
.to(Vec3(10, 0, 0), 1.0, ease_out_quad)
.wait(0.5)
.to(Vec3(0, 0, 0), 1.0, ease_in_quad)
.on_complete(lambda: print(“Done!”))
.build()Initialization
- build() simvx.core.descriptors.Coroutine[source]¶
Build the coroutine chain.
- simvx.core.animation.tween.tween(obj, prop: str, target, duration: float, easing=ease_linear, delay: float = 0, repeat: int = 1, on_step: collections.abc.Callable[[float], None] | None = None, on_repeat: collections.abc.Callable[[int], None] | None = None, on_complete: collections.abc.Callable | None = None) simvx.core.descriptors.Coroutine[source]¶
Time-based property tween generator with callbacks and repeating.
The coroutine driver sends
dt(per-tick delta time in seconds) on every resume; this generator accumulates it as elapsed time, so the animation runs in real time regardless of frame rate.Args: obj: Object to animate. prop: Property name to animate. target: Target value. duration: Animation duration in seconds. easing: Easing function (default: linear). delay: Delay before starting animation in seconds. repeat: Number of times to repeat (1 = play once, 2 = repeat once, etc). on_step: Called each tick with current progress (0.0 to 1.0). on_repeat: Called when a repeat cycle completes, with repeat index. on_complete: Called when all repeats complete.
Repeat semantics
The
startvalue is captured once before the first iteration. Every repeat replays the samestart -> targetinterpolation, snapping back tostartat the beginning of each cycle. Matches Godot’stween_property().set_loops(), DOTween’sLoopType.Restartdefault, and GreenSock’s defaultrepeatbehavior. For ping-pong or incremental modes, see therepeat_modeenum TODO entry.Example::
yield from tween( player, 'position', Vec3(10, 0, 0), 2.0, easing=ease_out_quad, delay=0.5, repeat=2, on_complete=lambda: print("Done!"), )
- class simvx.core.animation.tween.Tween[source]¶
Namespace for one-liner tween shorthands.
These wrap :func:
tweenfor the common case where the developer is just fading or tinting a node. They never construct a node, attach to a scene tree, or require anAnimationPlayer– yield from the returned coroutine inside aNodelifecycle method (run,on_process, etc.).Example::
# Fade a UI overlay to fully transparent over half a second. yield from Tween.alpha(overlay, 0.0, 0.5) # Cross-fade the modulate tint to red. yield from Tween.colour(sprite, (1.0, 0.2, 0.2, 1.0), 0.3)
- static alpha(node, target: float, duration: float, *, attr: str = 'modulate', easing: collections.abc.Callable[[float], float] = ease_linear, callback: collections.abc.Callable | None = None) simvx.core.descriptors.Coroutine[source]¶
Tween only the alpha channel of an RGB(A) colour attribute.
Sprite2Dexposes the channel ascolour;Sprite3D,NinePatch,MeshInstance2D, etc. expose it asmodulate. Passattr=when the node uses a different name.For 3-component sources the function transparently widens to RGBA so the alpha component can be animated; this requires the attribute to accept a 4-tuple (Colour Properties built with
has_alpha=Falsewill reject the widening and raise – that’s correct, you can’t animate alpha on an alpha-less colour).
- static colour(node, target: tuple, duration: float, *, attr: str = 'modulate', easing: collections.abc.Callable[[float], float] = ease_linear, callback: collections.abc.Callable | None = None) simvx.core.descriptors.Coroutine[source]¶
Tween a full RGB(A) tuple on
nodeoverdurationseconds.Source and target are auto-aligned: a 3-tuple target against a 4-tuple source is widened with alpha=1.0; the inverse truncates.