Line2D Texture Tiling

Godot Version

4.5

Question

The Line2D doesn’t tile. It stretches the right edge of the texture through the rest of the line, but it does not tile here. What am I doing wrong?

1 Like

Enable texture repeat.

1 Like

Thanks, but please describe where to find this option.

CanvasItem/Texture in Line2D node properties in the inspector.

The last suggestion mostly works, but it’s still stretching the texture except now its also tearing the texture.

Its not a complex sprite – its just a rounded white box. I haven’t figured out why this happens or if its a bug or this is just how the tiling feature works. But if I figure out anything new later this week I’ll be sure to share it.

I think Godot is using a mesh to warp the texture along the line2d, so perhaps something with mesh generation/triangulation is causing what you’re seeing. IDK what options exist to control that.

If you’re building a “marching ants” style line, have a look at Animated selection rectangle (Marching ants) - Godot Shaders

Otherwise, you might have to place the textures along the line yourself to get the effect you want.

1 Like

You can’t avoid this tearing due to way the texture is mapped on slanted quads. To somewhat alleviate this, use round joint mode and avoid sharp angles or add more points near them.

1 Like

Add more points, and stick to angles between 90 and 270 degrees if you can. If you want to play around with this, take a look at my Curved Terrain 2D plugin. There’s a demo project in there that updates as you edit points and uses the same texture. I’m doing the same thing but through code, applying a repeating Polygon2D to a line, then filling it with another texture.

The other thing you could do that might help is move the points so that they intersect where the polygon intersects (i.e. the blank spaces).

If it was me, I’d take a look at the CurverdTerrain2D code, and make a version that takes two textures, the second being a spacer that’s all set to Alpha 0 and code it so it alternates textures in the line.