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

#1

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.

0 Likes

#2

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
3 Likes

#3

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

0 Likes

#4

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

#5

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

2 Likes

#6

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

0 Likes

#7

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

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

0 Likes

#8

Thank you.

1 Like

#9

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.

0 Likes

#10

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