0 votes

So I thought this would work, but it expands one and contracts once, but then the second yield never gets triggered when I though this would be a way to get the node to grow and shrink repeatedly. It's almost as if, once a tween has fired an on_completed event, it never fires it again, even if you set it to start() again?

var tweenExpand = Tween.new()
var tweenContract = Tween.new()


# Called when the node enters the scene tree for the first time.
func _ready():

    add_child(tweenExpand)
    add_child(tweenContract)
    tweenExpand.interpolate_property(self, "scale", null, Vector2(2.0,2.0),2,Tween.TRANS_LINEAR)
    tweenContract.interpolate_property(self, "scale", Vector2(2.0,2.0), Vector2(1.0,1.0),2,Tween.TRANS_LINEAR)
    applyTweens()


func applyTweens():
    while true:


        tweenExpand.start()
        yield(tweenExpand,"tween_completed")

        tweenContract.start()
        yield(tweenContract,"tween_completed")
in Engine by (42 points)

1 Answer

0 votes

As you already noted, a completed Tween will not restart without calling the interpolate method again first. Once you do that, a loop can easily be implemented as shown here: https://godotengine.org/qa/24585/how-to-loop-a-tween-solved

by (1,742 points)
edited by

Why isnt this working then?

func applyTweens():
    while true:
        print("Tween Starting")
        tweenExpand.interpolate_property(self, "scale",  Vector2(1.0,1.0), Vector2(2.0,2.0),2,Tween.TRANS_LINEAR)
        tweenExpand.start()
        yield(tweenExpand,"tween_completed")
        print("tweenExpand Ended")

        tweenContract.interpolate_property(self, "scale", Vector2(2.0,2.0), Vector2(1.0,1.0),2,Tween.TRANS_LINEAR)
        tweenContract.start()
        yield(tweenContract,"tween_completed")
        print("tweenContract Ended")

This just generates this output then stops. It expands, contracts, expands then stops....

Tween Starting
tweenExpand Ended
tweenContract Ended
Tween Starting
tweenExpand Ended

Where as if I just use one tween instance to do the expansion and contraction it works, but I don't understand why.

func applyTweens():
    while true:
        print("Tween Starting")
        tweenExpand.interpolate_property(self, "scale",  Vector2(1.0,1.0), Vector2(2.0,2.0),2,Tween.TRANS_LINEAR)
        tweenExpand.start()
        yield(tweenExpand,"tween_completed")
        tweenExpand.interpolate_property(self, "scale",  Vector2(2.0,2.0),  Vector2(1.0,1.0), 2,Tween.TRANS_LINEAR)
        tweenExpand.start()
        yield(tweenExpand,"tween_completed")

I just tried your first script and it works just fine for me (Godot 3.2.1). Is anything else happening in your code which could affect / remove tweenContract during execution?

No that I am aware of. I am instancing these nodes, not sure if that makes a difference.

Could you upload your project (or an excerpt of it) somewhere?

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.