This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

How to draw primitives with alpha channel?

TTaykAHTTaykAH Posts: 4Member
edited June 2020 in GUI

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

Best Answer

  • TwistedTwiglegTwistedTwigleg Posts: 2,561
    Accepted Answer

    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)?


Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.