#Button color modulate tween causes flashed to/from black

9 messages · Page 1 of 1 (latest)

simple lantern
#

My Button gets a new color by it's parent ... it seems to 'flash' black now and then and I think when RGB channels do not overlap?

Code draws a rect in given color. Can I somehow prevent this flashing? Guess not using the module but change the color change steps myself?

extends Button

@export var color:Color = Color.WHITE:
    set(v):
        prints("color.set", color, '->', v)
        color = v
        flash()
        queue_redraw()

func _ready():
    custom_minimum_size = Vector2(400,400)

func flash():
    if is_node_ready():
        var tween = get_tree().create_tween()
        tween.tween_property(self, "modulate", color, 1)

func _draw():
    draw_rect(Rect2(Vector2.ZERO, size), color, true)

var ticks:int = 0
var colors: Array[Color] = [Color(1, 0, 0),Color(0, 1, 0),Color(1, 1, 0),Color(0, 0, 1),Color(1, 0, 1),Color(0, 1, 1),Color(1, 1, 1),]
var color_index = 0
var interval = 180

func _process(_delta):
    ticks+= 1
    if ticks % interval == 0:
        color = colors[color_index]
        color_index += 1
        color_index %= colors.size()
    if ticks % 10 == 0:
        printt(color)

simple lantern
#

Changing the colors using HSV values makes it little better. I still hope there is a better solution to transition between old and new color

var colors: Array[Color] = [Color.from_hsv(0, 1, 1),Color.from_hsv(0.1, 1, 1),Color.from_hsv(0.2, 1, 1),Color.from_hsv(0.4, 1, 1),Color.from_hsv(0.3, 1, 1),Color.from_hsv(0.5, 1, 1),Color.from_hsv(0.6, 1, 1),Color.from_hsv(0.7, 1, 1),Color.from_hsv(0.8, 1, 1),Color.from_hsv(0.9, 1, 1),Color.from_hsv(1.0, 1, 1),]
bright lodge
#

why does the flash happen in the first place? Like you expect the color to only change on initial setup? or is the color expected to change at runtime too?

simple lantern
#

That's why func _process(_delta): ticks (changing color) ... you can create a button scene and add the code.

bright lodge
#

Ok, just trying to understand the situation, so the flash is intentional, it just happens more often than you want?

simple lantern
#

I now think I misunderstand modulate.

What I want is when say Cell 45 wins Cell 44 the color of 44 changes into the color of 45 aka "green-ish" becomes "red" slowly

I ended up tween the color instead of modulate

simple lantern
#
extends Button

var next_color:Color
var color_step:float

@export var color:Color = Color.WHITE:
    set(v):
        color = v
        queue_redraw()

func _ready():
    custom_minimum_size = Vector2(400,400)

func flash():
    if is_node_ready():
        var tween = get_tree().create_tween()
        tween.tween_property(self, "color", next_color, 0.5)

func hsv_angle(c:Color) -> float:
    return c.h

func _draw():
    draw_rect(Rect2(Vector2.ZERO, size/2.0), color, true)
    draw_rect(Rect2(size/2.0, size/2.0), next_color, true)

var ticks:int = 0
#var colors: Array[Color] = [Color(1, 0, 0),Color(0, 1, 0),Color(1, 1, 0),Color(0, 0, 1),Color(1, 0, 1),Color(0, 1, 1),Color(1, 1, 1),]
var colors: Array[Color] = [Color.from_hsv(0, 1, 1),Color.from_hsv(0.1, 1, 1),Color.from_hsv(0.2, 1, 1),Color.from_hsv(0.4, 1, 1),Color.from_hsv(0.3, 1, 1),Color.from_hsv(0.5, 1, 1),Color.from_hsv(0.6, 1, 1),Color.from_hsv(0.7, 1, 1),Color.from_hsv(0.8, 1, 1),Color.from_hsv(0.9, 1, 1),Color.from_hsv(1.0, 1, 1),]
var color_index = 0
var interval = 180

func _process(_delta):
    ticks+= 1
    if ticks % interval == 0:
        next_color = colors[color_index]
        color_index += 1
        color_index %= colors.size()

        flash()

leaving effects out for now. Thanks!

simple lantern
bright lodge
#

I think that makes sense! Modulate applies a tint to the existing color, but I think can't really "overwrite" a color. Thanks for posting your solution here!