Godot Version
v4.5.dev1.official [97241ffea]
Question
I thought I’d start a simple new project that has a button which would have scaling up & down Tweening animations when clicked but after 2 days of trying I’m in need of some help.
My first hurdle was fixing the blurry “test” text when increasing the size of the button, this turned out to be because I needed to scale the font size instead of the Button node.
That seemed to do the trick though I needed to use the _process
function for it since I can’t use the add_theme_font_size_override
inside the tween itself.
This also made sure that the scaled up button properly worked with resizing the vboxcontainer to not overlap my second button, using scale didn’t do that.
Then I tried to trigger the animation a couple of times by clicking on it fast and noticed it blew up in size or shrunk down a lot, not the regular values(50 and 250) that it should have as start/end values.
I thought perhaps this had to do with the way it works inside the _process
function but printing out the current font_size_value each button pressed signal without using the _process
function also showed the values varying wildly.
I tried a lot from using different tween objects, to awaits, to passing the value to the Tween animation a different way, to if tween.is_processing() or tween.kill(), but nothing seems to solve it.
Is there any reliable way to get this working so I can fast-click the button as fast as I want and it always returning to one of 2 font size states while awaiting each other’s animations?
Here’s my current code that I ended up with:
extends Button
var big = true
var font_size_value = 50
func bigger_tween(tween):
tween.tween_property(self, "font_size_value", font_size_value + 200, 0.2).set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_OUT)
tween.tween_property(self, "font_size_value", font_size_value + 200, 0.3).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
func smaller_tween(tween):
tween.tween_property(self, "font_size_value", font_size_value - 200, 0.2).set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
tween.tween_property(self, "font_size_value", font_size_value - 200, 0.3).set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_OUT)
func _on_pressed() -> void:
print(font_size_value)
print(big)
var tween = get_tree().create_tween()
if big:
bigger_tween(tween)
else:
smaller_tween(tween)
big = !big
func _process(_delta: float) -> void:
self.add_theme_font_size_override("font_size", font_size_value)