How to use interpolate_callback on a Tween

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bob Dolan
:warning: Old Version Published before Godot 3 was released.

I am using the interpolate_property of a Tween object to scale a sprite, but now I want to pass arguments to the tween_complete handler. It looks like the only way to do this is with the interpolate_callback but I don’t see how they would work together.

I do this currently with the connect call on a Timer object with no problem but the connect call on a Tween does not accept args as a parameter.

How can I pass args to the connect call of a tween?

:bust_in_silhouette: Reply From: Skyfrit

interpolate_callback(object, times_in_sec, callback, arg1, arg2, arg3, arg4, arg5)

Example:

func _ready():
	tween.interpolate_callback(self, 3, "Call", "123")
	tween.start()

func Call(Arg1):
	print("Call ", Arg1)

Thanks for this.

My understanding of this is that the callback will be made in 3 seconds?

If so, I need to find a way to get a callback when the tween has completed and one that I can pass arguments to, the same way that the timer-complete callback does.

I have tried the following but it doesn’t work:

twn.connect("tween_complete", self, "TweenComplete", [id]) 
twn.interpolate_property(obj, 'visibility/opacity', start, end, speed, Tween.TRANS_QUAD, Tween.EASE_IN_OUT)
twn.interpolate_callback(self, speed, "TweenComplete")
twn.start()

The callback from a tween-complete passes the object and key. I tried adding the arg to the list, but no luck.

func TweenComplete( object, key, id ):

I feel like I am missing something but it isn’t apparent.

Bob Dolan | 2017-12-12 14:51

You can use get_runtime(), it returns the time for all tweens to finished in seconds.

func _ready():
	tween.interpolate_method(node, "set_opacity", 0, 1, 3, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
	tween.interpolate_callback(self, tween.get_runtime(), "Call", "123")
	tween.start()

func Call(Arg1):
	print("Call ", Arg1)

You can’t modify the default function, it doesn’t work.

Also, the tween*_*complete signal will emit every time when a tween ends, that mean if you have multiple tween, it will call tween_complete function multiple time.

func _ready():
	tween.interpolate_method(node1, "set_opacity", 0, 1, 3, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
	tween.interpolate_method(node2, "set_opacity", 0, 1, 3, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
	tween.start()

func Tween_tween_complete( object, key ):
	print("Call twice")

Skyfrit | 2017-12-13 09:34