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

+11 votes
Best answer
extends Node2D

onready var tween_values = [0, 10]

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

func _ready():
    _start_tween()

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

func _on_tween_completed(object, key):
    tween_values.invert()
    _start_tween()

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 (108 points)
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 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 webmaster@godotengine.org with your username.