My tween is not tweening! Want to animate changes in TextureProgress value.

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

Hello! For my 2D action RPG I’ve created an XP bar using TextureProgress, which fills as you make progress toward the next level-up. It works great, but I want to tween the value so the increase is animated, instead of making a sudden jump.

I put this in my _ready(): function

$Tween.interpolate_property($ExpUI_2, "value", start, end, 0.5, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

$ExpUI_2 is the TextureProgress bar node, ‘start’ is the initial value, and ‘end’ is the final value. And then whenever the XP changes, I call:

$Tween.start()

The bar continues to fill as before, and I’ve used print(start, end) to confirm that it’s correctly capturing the start and end values, but there’s still no animation - just abrupt jumps in the TextureProgress value.

Any obvious mistakes I’m making, or ideas for how to debug this problem? Thanks, y’all!

:bust_in_silhouette: Reply From: gramozilho

Hey, whenever your XP changes you need to call $Tween.interpolate_property( ... ) and $Tween.start() again:

$Tween.interpolate_property($ExpUI_2, "value", $ExpUI_2.value, end, 0.5, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
$Tween.start()

where $ExpUI_2.value will make the animation always start from the current position, avoiding the sudden jump

Yeah, I do have my variable “start” capturing the initial value and my variable “end” set capturing the updated value - the bar is correctly increasing from the current value to the updated one, the issue is that it doesn’t animate - just an abrupt jump (from, say, 25% to 50%).

samjmiller | 2021-08-18 16:24

Any chance the step value of the TextureProgress is too big to see the change?
This jump still happens with a larger tween time?

gramozilho | 2021-08-18 18:55

No - same problem when I increased the tween time, or tried smaller step values.

But I did solve the problem! I had to include

$Tween.interpolate_property($ExpUI_2, "value", $ExpUI_2.value, end, 0.5, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)

TWICE - in both the _ready(): function AND in the function that updates the XP.

¯_(ツ)_/¯

Thanks for your help tho!

samjmiller | 2021-08-19 20:57

That was my suggestion in the first answer! I’ll edit to make it more clear if anyone stumbles upon it in the future :slight_smile:

gramozilho | 2021-08-20 10:21

lol! Thank you for clarifying!

samjmiller | 2021-08-20 13:23