Size of the repeating sprite matters

I was playing around with another set of graphics and my parallax backgrounds wouldn’t repeat more than once. After a while I think I worked it out. Godot seems to only have 2 copies of the sprite. This means that part of the screen can be left without the background graphic. In my case I had a 300 pixel wide background that I wanted to repeat across a 1920 width game window.

I think that this means the sprite needs to be at least a little larger than the game window width to ensure that a continuous scrolling background is possible.

Can someone double check this? I’m a total newb with Godot and I could easily be mistaken.

Here’s a solution that Martin (Discord: m4rtini#1036) passed on to me.

Instead of spending time creating wider textures in an image editor replace the Sprite in Godot with a TextureRect.

  1. In the TextureRect set the texture to the image you want to use
  2. Enable the Expand setting
  3. Change the Stretch Mode to Tile
  4. In the Rect configuration section of TextureRect change the Size so the width is the size of the game window (or a little wider). Using multiples of the image size keeps things looking good.

Now the TextureRect will repeat itself and fill the width of the game window. The ParallaxLayer will mirror the entire TextureRect so you get a continuously sliding background. Just remember to set the Mirroring width in the ParallalLayer to the same width you set in step 4, above.

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms