0 votes

Hello, I'm new here. I want to create a tween to loop forever, with this setting :

a sprite which it's alpha will go back and forth from 0 to 1

Something like ping-pong / flip-flop looping.
I have tried making a 2 tween, one for 0 to 1 the other for 1 to 0. After that I have tried calling it with on tween complete to start each other but it just running once and done.

Someone please guide me trough this, thank you for reading.

in Engine by (66 points)
edited by

2 Answers

+13 votes
Best answer
extends Node2D

onready var tween_values = [0, 10]

func _enter_tree():
    var tween = Tween.new()

func _ready():

func _start_tween():
    $Tween.interpolate_property(..., tween_values.[0], tween_values[1], ...)    

func _on_tween_completed(object, key):

Or you could set up two tweens and make them call each other at the tween_completed signal. Connect the signal via the inspector tab "signals" or via code:

connect("tween_completed", self, "on_tween_completed")

That's all. :P

by (840 points)
selected by

thank you very much! I should have learn array more

It would've been a much more useful feature if tweens would have the "Tween.LOOP" trans stuff

that's genious

0 votes

animation player is your friend :)

by (116 points)

What happens when everything is dynamic? AnimationPlayer might not work

Sorry to necro, but it's an XY problem. The first thing I though was looping tween for a certain animation, because I wanted easing. So I googled how to loop tweens in Godot. However, this answer reminded me about the AnimationPlayer, which is what I really needed. I can easily create easing with keyframes, looping is supported out of the box, and animations can be created declaratively in the editor, so no extra cluttering in my scripts.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.