GDScriptBeta
Loops and delays
Ping-pong sends a motion back to where it started; repeats play it again. Together they make idle motion that runs on its own.
Examples use the global Tweens class in a node script, with targets inside the scene tree.
Loop forever
Section titled “Loop forever”var tween := sprite.create_tween().set_loops()tween.set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)tween.tween_property(sprite, "scale", Vector2(1.1, 1.1), 0.8)tween.tween_property(sprite, "scale", Vector2.ONE, 0.8)var pulse := Tweens.scale_2d([1.1, 1.1], 0.8, InOut.SINE) \ .with_ping_pong().with_repeats(Tweens.INFINITE)
Tweens.play(sprite, pulse)The sprite grows for 0.8 seconds, shrinks for 0.8 seconds, and repeats until cancelled or removed from the tree. Ping-pong returns to the scale the sprite had at the start, so the return leg needs no value of its own.
Count cycles
Section titled “Count cycles”| Set | Effect |
|---|---|
with_repeats(2) |
Three cycles: the first plus two repeats |
with_ping_pong() |
Each cycle goes there and back; duration applies to each leg |
with_ping_pong_interval() |
Pause at the far end before the return leg |
with_repeat_interval() |
Pause between cycles |
Try it: raise repeats, then drag the timeline to see where each interval falls.
Hold during a delay
Section titled “Hold during a delay”fill chooses what a delayed tween shows before it starts and after it ends. For an entrance, Tweens.Fill.BOTH applies the from value during the delay and keeps the final value:
var fade_in := Tweens.modulate_alpha()fade_in.from_value = 0.0fade_in.duration = 0.3fade_in.delay = 0.5fade_in.fill = Tweens.Fill.BOTH
Tweens.play(label, fade_in)The label stays hidden for half a second, then fades in to its own alpha. The default fill, RETAIN_FINAL_VALUE, would leave it visible during the delay, so it would blink out before fading in.
Each row below plays one delayed tween with a different fill mode:
tweens.gd is made with math & ferrets, copyright © 2026 its contributors.
Godot logo by Andrea Calabró, licensed under CC BY 4.0.
"Easy, the Ferret" illustrations drawn by foxy_maria.
tweens.gd is released under the MIT License.
Godot is licensed under the MIT License.
tweens.gd is not affiliated with or endorsed by the Godot Foundation.