Parallax Background pops in when mirrored / renders too late

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By okolaris

Hi everyone,

I just started learing how to use Godot and stumbled across my first issue. I did everything as shown in various tutorials but whenever I use the Parallax Background and set up mirroring the new mirrored part of the background renders just after the end is visible in the player camera. So basically the next background part pops up on camera so one sees that just repeats. I set the x-value for mirroring to be the same as the width of the background image (just some trees for testing, so there is no y-axis to mirror).

Here a screenshot: image

What am I doing wrong? When I use the same image in a lot larger it seems to work but then my player figure is way too small.

Thanks for your help! :slight_smile:

1 Like
:bust_in_silhouette: Reply From: soundgnome

Not sure if you figured this out already by I just ran into a similar problem today and thought I’d post what worked for me in case it helps someone else out.

The problem I ran into occurs specifically when the rendered sprite is smaller than the viewport - didn’t have to take these steps with larger backgrounds, but for smaller images you may have to:

  1. Check the “import” tab on your image asset and make sure “Repeat” is set to “Enabled” - Reimport if needed
  2. On your Sprite, set Region to Enabled, x & y to 0 and w & h to some multiple of your sprite size which will cover the viewport
  3. On your ParallaxLayer, set Mirroring to the same values as your Region w & h (multiplied by your Sprite’s scale factor if not set to 1)

Hope this helps!

Thankyou for the answer thats work for me to

AinsTempest | 2023-03-10 15:27

4 Likes
:bust_in_silhouette: Reply From: Canna71

Have you tried setting “Ignore Camera Zoom” in Parallax Background?
In my case that was the reason.

1 Like
:bust_in_silhouette: Reply From: FlipThis1

So I had the same problem, and readjusting my test window to the same size of the region w & h seem to fix it.
Apparently the window was longer than the refresh borders.

If you found a different solution, could you share?
New to Godot.

:bust_in_silhouette: Reply From: nastya.sim

In my case, the reason was that the sprite was centered.

sprite.centered = false

This fixed the problem.

3 Likes
:bust_in_silhouette: Reply From: Zelta

i tried all this and no way.

but works for me keeping the sprite position respective to its father to 0

i mean

not move the sprite position. centered = false

move the parallax layer

:bust_in_silhouette: Reply From: cinnabread

Select Ingore camera zoom, it makes the parlleax bigger though which may be a problem for you. Denpending on the size of your camera and the parlleax pictures it will load before the camera sees it. If this doesn’t work, rescale the picture(s) your using.

I had this problem when I was using ParalaxLayers to make an infinite scrolling vampire survivors style ground effect. The problem was the child sprite 2d that held the texture. under the Sprite 2d the Offset was set to Centered. My guess is that the texture keeps popping back to center. Turned it off and it works fine.

1 Like

This one worked for me, but I would like to understand why, In the documentation, they say that region_rect is “The region of the atlas texture to display. region_enabled must be true.” Which value is considered to calculate the paralax if I don’t make the region option? Does someone know the answer?

To give the simple explanation, regardless of how many children you have of a parallax layer and where they’re located, your “infinite repeat canvas” will always be the size of the motion_mirroring value you input starting at 0,0 going down and to the right.

My texture is 288x208, so I have the motion_mirroring set to 288,208. With this, my “infinite repeat canvas” is the size of the red rectangle. When the camera scrolls from the red rectangle to the orange one, it’ll zip all the children forward the length of the rectangle to make it appear like it’s infinitely repeating.

In the second example, you can see that the texture is not completely in the canvas. It’s up and to the left, so when the camera scrolls from the red rectangle to the orange one, half of the picture is cut off before it zips forward.

Hope this helps!

My solution if anyone finds this useful:

I was adjusting the position of the parallax background by transforming the position of the individual parallax layers. This is incorrect!

You need to set the transform position of the individual layers to 0, 0 (default), and instead do any position transformations via its parent Parallax Background.

In Godot 4, I was able to solve it this way:

In ParallaxLayer:

  1. Go to Motion and set Mirroring x to the same width as the image.

In Sprite2D:

  1. Under Texture, set Repeat to Enable.

  2. Under Region, set Enable On.

  3. In the fields that appear, set x and y to 0, and set w to a multiple of the image width, large enough for the image to be more than twice the width of the camera. Set h to the height of the image.

Tip: In the text field, you can type the width multiplied by an integer (e.g., 320*4).

2 Likes

You are a God amongst humans. THANK YOU!

1 Like