3
\$\begingroup\$

I have started learning to use godot and I've created simple 2D scene with a spaceship that you can control. I want to add some background so that you can see if you're flying or stopped.

I made an image 846x846 pixels and created a ParallaxBackground and a ParallaxLayer in it. This is how I set up the layer:

image.png

I did not change anything else.

However, when I run the game the background fails to catch up, when I fly in one direction, I will reach uncovered area, then it will get covered few moments later:

image.png

This is what it looks like in the editor:

image.png

It seems that the parallax background repeats the contents 4 times only. That makes pretty much impossible to cover the entire screen in all instances, so I bet that is the problem.

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

For my project, the solution to this issue was to uncheck the Centered property in the Offset group of each sprite child of a ParallaxLayer node:

uncheck centered property of Sprite2D

If you've set the Mirroring property of the ParallaxLayer to the correct dimensions (including accounting for any scaling on the Sprite2D nodes), this should align the textures correctly in the parallax background.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Worked for me, although I am not exactly sure why. I tried offsetting the parallax manually before, which seems a lot similar what this does, but it didn't work. Anyway, thanks for helping! \$\endgroup\$ Commented Oct 16, 2022 at 13:06
  • \$\begingroup\$ Hm, too bad you have to do this on every sprite. I added an offset parent at the very top with position offset = half-repeat size. I wish Godot would just auto-offset textures so it always work, but I understand why limiting the engine to two repetitions is optimal. This should be better explained in the doc/API doc though. \$\endgroup\$
    – hsandt
    Commented Aug 10, 2023 at 17:08
2
\$\begingroup\$

Incase someone's facing the same problem,

A solution is to enable repeat on your image in the import tab:
enter image description here

Then increase the sprite region_rect by *2 (or multiply by whatever suites you): enter image description here

and do the same in ParallaxLayer mirroring option

enter image description here

This should work, instead of manually increasing the texture resolution like an idiot which I definitely did not do for hours

\$\endgroup\$
1
  • \$\begingroup\$ While not incorrect, this fixes the issue by simply covering a wider area. So you still draw a rectangle the size of a full screen outside of camera view, but the area is so big that it covers the camera view anyway. See Problematic's answer for a way to fix offset without extra drawing (maybe camera clipping avoids extra cost anyway, I'm not sure how it works with repeated textures). \$\endgroup\$
    – hsandt
    Commented Aug 10, 2023 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .