Parallax background is very hard to make!

Godot Version

4.7.1

Question

I am trying to make my first game (i have zero experience but i will do it anyway) and probably i have watched more than 5 videos for Parallax background but everytime it doesn’t work properly.

I hope somebody can help me…

The first image is when i start the game:

You should post how you scene tree looks as well as the code for the parallax so we can help you out better

Have you tried reading the official docs?

They introduced a new node Parallax2D, that is the recommend over the older nodes. Potentially watching multiple tutorial videos is confusing things as they may be using different nodes.

Edit: More info about why the new node was added from the Godot Blog

I’d setup like that:

Level
├─ ParallaxBackground
│  ├─ ParallaxLayer # far (mountains)  motion_scale ≈ (0.2, 0.2)
│  │  └─ Sprite2D / TextureRect
│  └─ ParallaxLayer # closer (clouds) motion_scale ≈ (0.5, 0.5)
│     └─ Sprite2D
├─ TileMap / platforms
└─ Player
   └─ Camera2D   (current = on)

motion_scale of (1, 1) = no parallax. Lower = farther away.

I Have tried both parallax2d (new one) and parallax background (old one) but still same…

I think the problem is my background images are 320x180 but my viewport is 1152x648

If I set my viewport 320x180 it works fine but then it is too small to see or play. Like i said before i don’t know so much about coding so how resolution works i don’t know. But i want to learn…

Also my camera zoom is “4” maybe this could be a problem as well…

as other mentioned :->

try read documentation as there is nice guide

also posting your scene_tree and relevant script is the most relevant for others to be able see what’s going on your side.

The documentation for 2D Parallax mentions 4 ways to handle a texture that is too small:

  • Make the viewport smaller (seems you already tried and are not satisfied)
  • Scale the Parallax2D
  • Scale the child nodes
  • Repeat the textures

Did you try the later approaches?

I read it. It says set your viewport to same as background sprite. But it makes the camera and the game too small. I can almost only see my character…

I tried but didn’t work again…

scene_tree example :

script example :

class_name Player extends CharacterBody2D

func _physics_process(delta: float) -> void:
	pass

also if you have Parallax2D the Inspector properties be nice to share as well.

I read it but couldn’t find a solution to my problem…

Both your scroll scales are set to 0. It looks like you want to move in the x-direction, so set your scroll_scale x to 1 to move at the same speed as the viewport, less than 1 (0.8 say) to scroll slower than the viewport (looks like it is further away like a background) or higher than 1 (1.2 say) to scroll faster than the viewport (looks nearer to the camera like a foreground).

Only background is 0, others 0.3 / 0.5 / 0.7

I even rebuilt the things i have done but still couldn’t solve it…

I guess i won’t use parallax background. Thanks for the answers

Don’t give up yet! And that is not a solution! Parallax layers are genuinely simple and robust. So something somewhere is breaking and you have not found it yet. But it is not the parallax layer.

Paste your background image here and I will do a simple mock up for you.

Don’t shrink the viewport to 320, that only makes the whole game tiny. Keep 1152×648 (or whatever), and make the art fill the view.

With Camera2D zoom 4, you only see about 1152/4 ≈ 288 world-pixels wide. A 320-wide sprite is barely one screen, so it looks “broken” unless you scale and/or repeat it.

On each Parallax2D (you already have follow_viewport on == good):

Far sky: scroll_scale (0, 0) is fine (doesn’t move)
Other layers: (0.3, 0), (0.5, 0), (0.7, 0) — not all zeros
repeat_size.x = texture width (320)
Scale the Sprite2D up (or the Parallax2D) until it covers the zoomed view
Parallax2D is the right node for 4.7; ignore old ParallaxBackground tutorials if they fight you.

Docs walk through the “texture too small” options: 2D Parallax — Godot Engine (stable) documentation in English

At least try one more time, giving up is never should be an option.

Each to to their own, but for pixel art games you should absolutely set the viewport to something akin to an equivalent of what would have been a retro resolution.

So for example for 1080p , 384x216, with integer scaling set to 5.

Thats exactly what should be done.

I have solved my problem… The first thing i did was rebuilding the things i have done with my new size settings and camera settings (i have changed zoom, viewport settings etc. and it took half hour because i was still in the beginning)

Then i have used autoscrolls for parallax backgrounds… (with ignore camera setting)

And the last thing i did was changing stretch mode from “viewport” to “canvas_items” and it solved my camera jittering problem…

and here is the result: (i can’t share video i guess so you can’t see clearly but background is moving towards left (with different autoscroll pixels) and looks cool i think… for now…)

It isn’t following the camera anymore but i am fine with my new background…