How does a 2D game fake depth? Parallax scrolling and background layers explained
Walk through a game level and the faraway mountains barely move while the trees rush past. That trick is parallax scrolling, and it makes a flat 2D screen feel deep.
Drag a five-layer scene yourself, then switch the depth off to see what changes. You will learn the single number that sets each layer's speed, how backgrounds repeat forever, and the mistakes that make parallax look wrong.

Walk across a game level and the background does not slide past at the same speed as the ground. Distant mountains creep, nearby trees rush by, and the flat screen suddenly feels deep. That trick is called parallax scrolling, and it costs almost nothing to build.
Why far things move slowly
Look out of a car window. Fence posts beside the road blur past, a barn across the field drifts by, and the hills on the horizon barely seem to move at all. Your eyes are doing the same thing a game camera does: when you move sideways, near objects shift a lot and far objects shift a little. Your brain reads that difference as distance.
A 2D game has no real distance, so it fakes it. The level is split into layers stacked back to front. When the camera moves, every layer slides the opposite way, but each by a different fraction of the camera's movement.
Try it: move the camera
Drag the scene left and right, or use the slider. The five layers are the sky, far mountains, hills, trees and the ground. Then turn the depth strength down to zero and see what the same scene looks like with no parallax.
The one number that does it
Each layer gets a parallax factor, a number between 0 and 1. The layer's position on screen is simply:
layer_x = -camera_x * factor
A factor of 1 means the layer moves exactly with the world, like the ground you stand on. A factor of 0 means it never moves, like a painted sky. Everything in between sits somewhere behind the action. In the demo above the layers use roughly 0.05, 0.2, 0.45, 0.75 and 1.
Notice what the game does not do: nothing is calculated in 3D, and nothing checks distances. Each layer is just a picture shifted by a different amount. That is why the effect works on a phone from a decade ago.
Making a layer repeat forever
A level can be long, but a background picture is a fixed size. The trick is to make each layer a seamless tile: the right edge matches the left edge. The game draws the tile twice side by side and wraps the position back with a remainder (modulo) operation, so when one copy slides off the screen the other is already there. In the demo each layer repeats this way, which is why you can drag as far as you like and never run out of scenery.
Slower layers need less artwork variety, because they scroll through their tile more slowly. A mountain range can be one wide picture. The fast layers closest to the player usually need more detail, since the eye has time to notice repeats there.
Where it goes wrong
Parallax is a trick on the eyes, so a few things can spoil it or make people uncomfortable:
Wrong order. If a distant layer moves faster than a nearer one, the scene looks like it is spinning backwards. Factors should always grow from back to front.
Too much motion. Big, fast-moving foreground layers can make some players feel queasy. Many games offer a way to reduce camera motion or screen shake, and it is a good option to add to your own game too.
Gaps and jitter. Layers that move by fractions of a pixel can shimmer. Pixel-art games often round each layer's position to whole pixels so the edges stay crisp.
Mixing up scenery and gameplay. Only the layer the player walks on should count for collisions. Background layers are decoration, even though they move.
Try it in your own game
Most beginner-friendly engines have parallax built in. Godot has a Parallax2D node (older versions used ParallaxBackground and ParallaxLayer), where you set a scroll scale per layer. In Unity and other tools you can write the one-line formula above and apply it to each background sprite. Start with three layers, give them factors like 0.2, 0.5 and 1, and compare the result with all three set to 1.
Once you have felt the difference, you will start noticing it everywhere, from side-scrollers to menu screens with a slowly drifting background. It is one of the cheapest ways to make a flat game feel like a place.
More in Making Games
all Making Games →2 Dec How do games branch a conversation? Dialogue choices, flags and locked answers Dialogue in games is a map: each line of text is a node, and each answer is a road to another node. Add a few flags and numbers the game… Making Games
16 Nov Why do menus and movements feel smooth? Easing and tweening explained Press a button in a game menu and the panel slides in, slows down and settles. That feel comes from easing: changing the speed of a… Making Games
3 Nov How do games make fire, smoke and sparks? Particle systems explained Fire, smoke and sparks in games are usually not drawings or videos. They are swarms of tiny short-lived particles made by an emitter. This… Making Games
1 Nov How does an enemy find its way around a wall? Pathfinding and A* explained How does an enemy find its way around a wall? Walking straight at you works only until the first obstacle. Pathfinding treats the map as a… Making Games
30 Oct How do game mods work? Load order and why the last mod wins Ever installed two mods and watched one quietly stop working? A mod is a small package that swaps or adds the data files a game reads, and… Making Games
28 Oct How does a game know two things touched? Collision boxes, circles and bullets that pass through walls How does a game know that two things touched? It doesn't look at the artwork. Every object gets a simple invisible shape, and the game…