Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a 2D game in Unity, but this would apply to any 2D game engine.

If I implement multiplane parallax with orthographic cameras, it is difficult to lay out the background layer's sprites and know where they will line up with sprites in other layers.

My first instinct was to use multiple cameras, one for each layer, and scale down the movement speed of cameras for background layers. This avoids having to move all background sprites every frame. The problem is that a layer that moves at half speed will take up half the space of the main layer when viewed in the editor. So it is difficult to know where to place sprites as you're laying out the game. The problem gets exponentially worse as you increase the number of layers.

How do I get around this? I've tried inversely scaling the layers by their intended movement speeds while working with them in the editor. That puts all background sprites in the correct locations relative to the main layer, but they're horribly distorted.

Do I need to just suck it up and constantly switch between the editor and the running game to test the parallax backgrounds?

share|improve this question
When I did a game like that I just made it so you could drag around the camera in the editor and you could see how the parallax worked. I'm not sure off hand how to specifically do something like that in Unity, though. – Tetrad Jan 26 '13 at 17:16
up vote 1 down vote accepted

I'm unfamiliar with Unity, so I cannot help you with specifics, but it sounds like what you need is to implement a GUI means of fine-tuning those values during run-time with, say, a set of sliders or numeric fields. It would be fairly simple to implement fields to alter whatever values you're determining (scale, speed, etc) during run-time which gives you immediate feedback. For placement, you could use either fields or manual placement with click-dragging (which might be slightly harder to implement, but much more intuitive).

This gives you complete control without compiling and running the code for every small fraction of a change. When you finally arrive at a look and feel with which you're happy, use those values in your list of constants. If this is too daunting because of the number of variables you're editing (say, numerous sprite locations in numerous levels), you would want to implement it in a level editor, I imagine, with the same functionality of manual adjustment but with the result of creating and storing the data adjusted.

share|improve this answer
Yes, it seems using a level editor is the best way to do it, whether it's coding your own, or in my case with Unity, setting it up to work with the existing editor. I coded my paralax setup with a separate camera object for each layer, and the cameras each get moved appropriately relative to the main camera each frame. Then use [ExecuteInEditMode] to get them to update even when the main camera is dragged in the editor. I just need to remember to only move the main camera directly. – TenFour04 Jun 1 '13 at 23:37

An idea: I would think a camera for the front layer is enough. Placing sprites a distance away from that on the z plane, and lerping the distance gives you a fraction on which to move that back layer.

For example, an object distance 10 from the front camera moves 1/10 in the background layer. An object of distance 2, would move 1/2 in its respective layer, etc.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.