How do I check if the Alpha of my gui node is 0? Also How do I change it?

I want to check if the Alpha of my node is 0, and if it is I want to turn it to 1, and vice versa. This is just for a toggle feature.

Set

local alpha = 1
gui.set_color(vmath.vector4(0,0,0,alpha))

Get

local color = gui.get_color(gui.get_node("my_node"))
local alpha = color.w
4 Likes

Doing gui.set_color(vmath.vector4(0,0,0,1)) turns my gui node fully black, why is that?

The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.
Link to wikipedia

Black is the absence of color, and white is all the colors together

3 Likes

Oh okay so to keep the original colors of the node I have to make it white

2 Likes

I had the same problem, but when I change the rgb values to white, the node is white?

White:
gui.set_color(node, vmath.vector4(1,1,1,1))

Black:
gui.set_color(node, vmath.vector4(0,0,0,1))

Thank you.

1 Like

You need to gui.get_color first, and put that into a vmath.vector4 variable. Change that variable’s alpha channel to 0 and then gui.set_color.

There’s a feature request for a gui.set_alpha() here: https://github.com/defold/defold/issues/5429

Makes sense to be honest! It is very common to manipulate only alpha on gui nodes.

3 Likes