Tween and button styles

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

Hello there,

I’m trying to tween the background color of a button

here is what I’ve got so far :

func go_tween():
    var style = get_stylebox("normal")
    tween.interpolate_property(style, "bg_color", col_start, col_error, 1,Tween.TRANS_LINEAR, Tween.EASE_IN_OUT);
    tween.start()
    yield(tween, "tween_complete")
    print(style.get_bg_color())

The color is updated during the tween but the button doesn’t update its background color until I hover it with the mouse.

Any ideas ?
Thanks !

The button doesn’t update because the Style is a Resource, and it looks like the Button only updates from the resource when it changes state. You can try to call button.update() every frame while the Tween is active, which is not convenient indeed but could fix the problem.

Zylann | 2017-02-12 01:29

Yup, it works. Thanks !

I hope there is another way … this doesn’t feel right :slight_smile:

leg0 | 2017-02-12 18:41

The button.update() can be called on tween_step signal too, still not ideal but is another option to notify the resource changes.

And does not matters when or how many times you call update, it will redraw when it can (idle) so even if does not feel right, Godot does it right :stuck_out_tongue:

eons | 2017-02-13 10:43

:bust_in_silhouette: Reply From: Vladimir
tween.interpolate_property(get_stylebox("normal"), "bg_color", get_stylebox("normal").bg_color,  Color.greenyellow, 0.15)

For me it’s work