Hello, should be said that I'm new in Godot and don't now much, but resently I faced a problem with drawing transparent primitives. I need to draw grid that won't overlap background images a lot. For example I built simple tree:

And I have this code in DrawGrid node's script:

extends Control

export var lenX = 50
export var lenY = 28
export var tile_size = 16
var screenx
var screeny

func _ready():
	screenx = get_viewport_rect().size[0]
	screeny = get_viewport_rect().size[1] 
	
func _draw():
	
	for i in range(lenX):
		var x = i*tile_size
		draw_line(Vector2(x, 0), Vector2(x, screeny), Color(255, 255, 255, 100))
		
	for i in range(lenY):
		var y = i*tile_size
		draw_line(Vector2(0, y+1), Vector2(screenx, y+1), Color(255, 255, 255, 100))`

Despite I specified alpha channel as 100, It drawing with alpha=255. How can I fix this and is it even possible? P.S. Sorry for my English, I still learning :0

Welcome to the forums @TTaykAH!

I do not remember right off, but I think the color constructor takes (or can take) values from 0-1, so maybe try the following and see if it works: Color(1, 1, 1, 0.5)?

God... I couldn't even think that alpha chanel fork with values in 0-1 range. I changed color to Color(255, 255, 255, 0.1) and its work. Thanks for your answer.

The main thing here is that you're using Color() which only takes float values from 0 to 1 for each entry. Anything above 1 is just clamped to 1 (ie: 100%) If you want to work with 0 - 255 integer range, you need Color8() to create the appropriate Color from those numbers. IE: Color(1.0,1.0,1.0,.1) vs Color8(255,255,255,26) being equivalent (i'm rounding here, you're getting 1/10th of 255)

https://docs.godotengine.org/en/stable/classes/class_@gdscript.html?highlight=%40gdscript#class-gdscript-method-color8 https://docs.godotengine.org/en/stable/classes/class_color.html?highlight=color#class-color-method-color

18 days later

Anything above 1 is just clamped to 1 (ie: 100%)

This is not actually the case (except for alpha). Unlike Color8, Color allows inputting "overbright"/HDR colors whose components can go towards positive infinity. Only alpha is clamped to 1.

2 years later