How to make line2d's some parts have different transparency values

Godot Version

4.4

Question

In paint.net i can do this below, so when i modulate this sprite node, red rectangled area becomes a little bit transparent while carrying the modulate color shade.

I don’t know how to achieve this with line2d. Above method caused me some issues when i try to draw and connect lines (neighboring sprites) so i need to achieve this with line2d. Both sides (above and below) should have transparency

Probably use gradient and set alpha as appropriate along the gradient.


Can you show me some examples? Can i do these “precise” transparency transitions with 1 line2d object, or do i need two more to handle above and below transparency. Also i couldnt find how to make it top down

It depends on how you want to do the transparency. If you want to make the line fade along the line, I think gradient is the solution. If you want to make the line fade so there’s a strip of translucent along the entire length of the line, I think instead you want to use a textured line.


I think i found a way but dunno if there is better one
1 and 3 have the red shade as you see.
These three parts will have same width(they will follow each other). 1 and 3 will have half height of 2.
they will have same modulate but 1 and 3 will have alpha 31 out of 255.

So under Node2D having three line2d can help me achieve this?

I think you can do that with a single line2d by setting that as texture and setting texture_mode to LINE_TEXTURE_STRETCH.

Basically, give it a cross section of the line as a texture, and tell it to stretch that along the whole line.