Parallax
A scrolling technique that moves layered background planes at different speeds to create an illusion of 3D depth in 2D scenes
Table of Contents
Interactive Playground
Tap or drag to interact with the demoWhat is Parallax?
A scrolling technique that moves layered background planes at different speeds to create an illusion of 3D depth in 2D scenes. It is a core concept in Game Graphics Tech within Game Dev.
Core Principles
Parallax scrolling mimics the real-world optical phenomenon of motion parallax: when looking out a moving train window, nearby trees rush past quickly while distant mountains barely shift. By splitting a 2D scene into multiple depth planes and multiplying camera movement by different speed factors, developers create convincing spatial depth without full 3D geometry.
A typical stack separates distant sky/clouds (0.1×), mid-ground silhouettes (0.4×), the active gameplay plane (1.0×), and close foreground elements (1.25×–1.4×).
Practical Takeaways
- Preserve gameplay readability: Distant layers should never compete visually with the player or hazards. Apply atmospheric perspective—lower contrast, softer saturation, and subtle tinting toward the sky color—as layers recede.
- Use foreground layers sparingly: Fast-moving foreground silhouettes (
>1.0×) add dramatic depth, but keep them near screen edges or semi-transparent so they never obscure enemies or platforms. - Loop seamlessly via UV offset: Instead of duplicating massive background sprites, wrap tileable layers using shader UV offsets or modular two-panel recycling to keep memory usage low.
Notable Examples
- Ori and the Blind Forest: Stacks over a dozen painterly parallax planes with subtle depth-of-field blur for a lush, living forest.
- Hollow Knight: Pairs shadowed foreground pillars with towering distant ruins to give underground caverns immense scale.
- Sonic the Hedgehog: Pioneered multi-band raster parallax scrolling to amplify high-speed platforming sensation.
Practical Code Snippet
Copy and drop straight into your projectinterface ParallaxLayer { element: HTMLElement; depth: number; // 0.1 = far sky, 0.8 = near foreground} export function updateParallax(layers: ParallaxLayer[], cameraX: number) { for (const { element, depth } of layers) { const offsetX = -cameraX * depth; element.style.transform = `translate3d(${offsetX.toFixed(1)}px, 0, 0)`; }}