- Home /
2D Parallax Background
I would like to made a 2D scrolling game (up,down,left,right) which uses parallax with its background. So the player would appear to move slowly across of it. Any pointers on how to go about accomplishing this task?
Answer by skovacs1 · Dec 13, 2010 at 04:17 PM
Multiple "planes" (at least the front of which with transparency) at different depths, "moving" at different speeds relative to the camera.
You "planes" could be planes or cylinders or spheres as you like.
"Moving" your background is up to your discretion. If using tiled textures, then you would simply change the offset. If using the actual geo, you would move them at different speeds.
An alternative setup is to have a second camera render your different depth to a RenderTexture, but that is Pro-only and somewhat overkill.
Haha, you're the one that posted on the link I posted =).
I am, but that question was looking for a custom camera rotational control, hence why I provided a different and much simpler answer here.
Without the pro version, you can also use multiple cameras to achieve a parallax effect, and it's actually as easy - or maybe easier - than the method described above.
All you have to do for this to work is to assign your scene objects to different custom layers (e.g. Foreground, Background1 and Background2). Next, you'll have to set the 'Depth' value of your cameras, so they are rendered in the correct order (back to front) and 'Clear Flags' needs to be set to 'Depth only' for all cameras except the one rendering the farthest background. Then, the only code required is to move the background cameras at a slower speed than the foreground camera.
Hey Bernard! Is this solution ressource hungry ? Would it run smoothly on a mobile device ?
@$$anonymous$$_Plot: It's definitely possible on mobile, and also does have an impact on the performance (probably increasing the amount of draw calls), but whether this is an issue depends on the other performance heavy things you may be doing.
Compared to rendering to a render texture, it would be faster (or at least as fast), and in terms of memory usage, it would be definitely better.
Answer by Justin Warner · Dec 13, 2010 at 04:16 PM
Enjoy =).
I'd personally make a cylinder big enough, apply the background, and just have the cylinder to rotate, but then again, that'd be a horrible way of doing it, haha.
I think this is a lot more complicated than what I need, thanks though. I'm sure it will come in handy sometime.
Answer by NorthernEagle · Apr 30, 2012 at 11:50 PM
Some great answers here. I'm gonna try adding 3 planes, one behind the other and just adjust the speed of them scrolling depending on their position relative to the camera. Closest scrolls fastest, etc... Thanks for the tips guys and gals!
Answer by BASICSPACE · Jul 03, 2014 at 02:38 PM
Try using seamless repeatable textures for backgrounds and foregrounds and render them on a quad scaled to the camera's vieport. This technique is very lightweight and easy to set up. This one might be usefull: http://vimeo.com/98545927
Your answer
Follow this Question
Related Questions
parallax scrolling background 2 Answers
Parallax scrolling background performance problem 4 Answers
Moving Background with translated images 1 Answer
trouble with getting the background to show past the midground in 2d parallax backgrounds 0 Answers
How to create an infinite scrolling background in top down multi-directional shooters. 2 Answers