new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Godot 4 Patterns · all subjects

tween_animations

14 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

create_tween() ownership and lifecycle

create_tween() returns a Tween object owned by the calling node. When the node is freed, the tween dies automatically. This means any tweens created on a node will be cancelled if that node is freed from the scene tree.

Tween property paths with subproperties

Property paths in tween_property can use dot notation to animate subproperties. Examples: 'position:x' animates only the X component, 'position:y' animates only the Y component, 'modulate:a' animates only the alpha channel. This allows fine-grained control without affecting other components.

Easing and transition combo for UI smoothness

For smooth UI animations, use EASE_OUT + TRANS_CUBIC. For bouncy effects use EASE_OUT + TRANS_ELASTIC. For punchy attack animations use EASE_IN + TRANS_BACK. For timer-like linear progression use EASE_LINEAR + TRANS_LINEAR.

Sequential vs parallel tweens

By default, tweens are sequential — each tween_property call waits for the previous one to complete. To run tweens in parallel, either call parallel() before adding a tween (for one-off parallelization), or call set_parallel(true) on the tween at creation time (for all subsequent tweens). Using set_parallel(true) makes ALL subsequent tweens parallel, while parallel() applies only to the next tween.

Tween delay, interval, and callback methods

set_delay(seconds) adds a delay before a tween property starts. tween_interval(seconds) pauses the tween sequence for a specified time. tween_callback(func) executes a function at that point in the sequence. tween_callback(method_name) calls a method. finished.connect(callback) fires a signal when the entire tween completes.

Slide-in toast notification pattern

To animate a toast (achievement notification) sliding in from the right, set the panel's starting position off-screen (e.g., position.x = 420), then tween position:x to the visible position (e.g., -16) with EASE_OUT + TRANS_CUBIC over 0.4 seconds. Add a tween_interval(3.5) to hold it visible, then tween back to the hidden position over 0.4 seconds.

Fade in then fade out pattern

To fade a node in and then out, set modulate.a to 0.0 initially. Create a tween and call tween_property(node, 'modulate:a', 1.0, duration) to fade in. Add tween_interval(hold_duration) to keep it visible. Then tween_property(node, 'modulate:a', 0.0, duration) to fade out.

Kill tweens before creating new ones on same property

If you create multiple tweens on the same property without killing the old one, they will fight each other. Always check if a previous tween exists and call tween.kill() before creating a new tween on the same target and property. Store the tween in an instance variable and check with 'if _current_tween: _current_tween.kill()' before reassigning.

Don't rely on tween_callback for critical scene transitions

Using tween_callback to trigger critical flow like scene changes is unsafe. If the tween fails (parent node freed, target invalid), the callback never runs and the scene transition never happens. Instead, use a Timer node in parallel with the tween for visuals. The Timer is decoupled from the tween and will trigger the transition regardless of whether the tween completes.

SceneTreeTimer vs Timer node for delays

SceneTreeTimer is one-shot, created with get_tree().create_timer(duration), and requires no node. Timer is a scene node, visible in the editor, pausable, and more controllable. For critical flow control like scene transitions, prefer Timer node because it is easier to debug and won't freeze if the calling node is freed.

Tween death when node is freed

If you call await tween.finished from a freed node, the coroutine will freeze because the tween is destroyed when the node is freed. Avoid relying on tween.finished for control flow on nodes that may be freed during animation.

Tweening modulate.a does not disable input

Fading out a node by tweening modulate:a to 0.0 only changes the visual appearance; it does not disable input handling. To prevent a faded node from receiving clicks or input, you must separately set mouse_filter = IGNORE on the Control node.

set_parallel(true) affects all subsequent tweens

Calling set_parallel(true) on a tween makes every subsequent tween_property call in that tween run in parallel. To run only one tween in parallel with the previous one, use the parallel() method instead, which applies only to the next tween.

Tween_callback sequencing is sequential by default

By default, tween_callback executes after the previous tween_property completes, not during it. If a callback appears to run before a property finishes, verify the timing with print statements, as the sequential behavior can be subtle.

Give your agent this brain