I'm developing a 2D Platform game, I have a 2D camera, some backgrounds, and everything is working good. Now I want to implement parallax scrolling to give the illusion of depth in my game, but i can't imagine how to make my different layers of background to move (most correctly, be rendered by the camera) with a different speed from each other).

In brief this is my game structure:

I have 3 layers of backgrounds: the first is the road level, where the player runs; the second is the intermediate; the third are some mountains very distant (in my mind). Everyone of these layers is created with seamless textures and organized with the tilemap technique, with every texture positioned one after the other. Of course I make the spritebatch draw only the visible ones.

The camera is a rectangle that follows player movements and goes just horizzontaly.

Since layers aren't moving, but only the camera is moving, I don't know how to make a background scroll with a different speed from another!


1 Answer 1


You just move the backgrounds despite them being meant to be static.

  • For example, your character (and the camera) move 5 units to the right.
  • Move the background right behind the character to the right by 1 unit.
  • Move the background behind the other background by 2 units.
  • Move the next background by 3 units, etc.
  • The furthest away background (i.e. the background supposed to be static) is moved with the player/camera (here: 5 units).

Doing this will already create the parallax effect you're looking for.


Move your backgrounds with your camera, where the actual movement is a function based on the camera's movement and the distance to/behind the screen. The further away something is, the more you move it (so it appears static).

This can get a bit tricky drawing wise, but you'll essentially just have to draw your backgrounds twice at most (so it always fills the screen, no matter the offsets).

  • \$\begingroup\$ Actually you'll want the closest things to move faster than the furthest things. IE your furthest away background should only move 1 unit while your layer right behind the character may move 4. \$\endgroup\$ Commented Sep 11, 2013 at 15:57
  • \$\begingroup\$ Correct, but if you move the camera, you'll have to move the furthest away back together with the camera (i.e. the fastest). Essentially it appears reversed, but that's correct unless your camera is static (then you'd be right). \$\endgroup\$
    – Mario
    Commented Sep 12, 2013 at 9:37
  • \$\begingroup\$ Ah, that makes sense. I've always used a static camera. \$\endgroup\$ Commented Sep 12, 2013 at 15:29