My tween.start() only works once

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

HI All. I have a tween set up do shake the clock sprite when timer reaches a certain low value. When the value goes up (after the player has collected a gem) another tween is set off that has a reverse effect to the first one. The conditions for that are in the process function. This works but only once. Ie, the timer goes below 10 - clock does the 1st tween. Timer goes up above 10 - clock does the other tween. But after this, when timer goes back below 10 again, the tweens don’t work… Does tween.start() only work once? Can you somehow ‘reset’ a tween after it has played?

It should be easy enough to do, but it’s hard to point to a problem without seeing the relevant code. Can you post it?

jgodfrey | 2020-02-15 19:58

It’s something like this:

func _process(delta):
	powerbar.set_value(MyTimer.time_left)
	if powerbar.value <= 10:
		tween1.start()
	if powerbar.value >= 10:
		tween2.start()	

Both tweens work once. When timer gets below 10 for the second time, tween1 doesn’t work any more…

Macryc | 2020-02-15 20:24

And, how are those 2 tweens defined?

jgodfrey | 2020-02-15 20:30

Additionally, that logic looks suspect. I mean, powerbar.value would always be either

  • = 10 … or …

  • <= 10

So, it seems like you’re firing one (or both when the value = 10) of the two tweens in every frame. I doubt that’s what you want…

jgodfrey | 2020-02-15 20:36

Yea, it took me a moment to realise this. They were firing up 60 times every second, ither one or the other. I put the 2 tweens each it its own function outside of process and set up an on/off toggle ‘mechanism’ with booleans. This solved the problem. Thanks for responding.

Macryc | 2020-02-15 21:45