+1 vote

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!

Godot version 3.2.3
in Engine by (127 points)

1 Answer

0 votes
Best answer

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

by (46 points)
selected by

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%).

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

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!

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

lol! Thank you for clarifying!

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.