How to make background repeat in a specific way

I have a 2D game with a Sprite2D that serves as the background. I need this background to repeat and I found a repeat option, but the problem is that I need the background to repeat the full sprite in the x axis and repeat the last pixel in the y axis (the higher part of the background is a sky color and I want it to repeat).

Hi,

According to this thread, making a sprite repeating differently on both axis is not trivial. A thing you could do is using a Polygon2D node that will make the repeating easier, and use a custom shader to adjust the x and y axis yourself.
Something like this:
repeat

Here’s the shader in case you want to give it a try:

shader_type canvas_item;

void fragment()
{
	vec2 uv = UV;
	uv.x = fract(uv.x);
	COLOR.rgb = texture(TEXTURE, uv).rgb;
}

Would something like this work for you, or do you absolutely need to use a Sprite2D node?

2 Likes

That will work, thanks a lot!

1 Like