- Home /
Infinite Scrolling 2D Sprite background
I currently am using a 2d sprite as the background and want to achieve a sort of parallax effect(though just having the sprite move to some point and being updated back to its starting point would be fine too).
How can I make it appear as if the player is infinitely moving forward when reality it is the background looping? I want to stick with 2d sprite as the bg so long as it doesn't pose any performance issues on mobile by modifying its position often. Not sure what's optimal or if I should even worry about it at my early knowledge of unity.
What I have tried: Using a texture (jmported bg image) applied to a quad with a directional light. This didn't work for me as it covered my player and enemy sprites and/or left a flare effect even though I made sure to not enable the flare (or at least I thought so).
Thanks.
I tried this myself for a game once. There is a way to loop a texture on a plane, or quad or something like that. What we came up with, is a cilinder with a texture on the curved part. When you start moving your character to the left or right, the cylinder will follow the sideways position and also rotate at the same time. This way you will have an endless background.
If you want to make parallax effects, you can use the same idea. $$anonymous$$ake multiple cylinders with transparent textures. Rotate one cylinder slower than the other one and voila.
This may not be the best way to do it, but its easy to set up, and a good solution until you find something more complex.
Tip: Dont make the circumference of the cylinder the same as the width of your texture, unless you have a very wide texture. Its best if you tile your textures side by side a couple times, so you can use bigger cylinders. That way you will not see the curvature and it will look like a flat background.
Answer by febucci · Sep 11, 2016 at 04:01 PM
In our game we use 2 sprites for the background. The same image obviuously, and we use a looped animation. When the first image goes out of the camera bounds, it comes back to the start position. Both scrolls and the mechanism is the same. You don't have to worry about scripting or something. If you want it to scroll when the game is paused just set the animator and set the time from normal tu unscaled. You can control the speed by script (Dont change it every frame, or you'll have impact on performance) Just play a bit with this, try and see if it works. Hope it helps
Edit: I forgot to say that you have to attach the gameobject with those 2 sprites to the camera, because if you don't do that they will be in world position and dont follow the camera
Answer by pako · Sep 11, 2016 at 11:00 AM
There is a very nice Unity tutorial that shows a few alternatives on doing this:
https://unity3d.com/learn/tutorials/topics/2d-game-creation/2d-scrolling-backgrounds
Answer by Dream_in_code · Sep 11, 2016 at 11:00 AM
If the texture with the quad didnt work just use perspective camera. Place your background image further away.Perspective camera will automatically create depth and parallax view without any codes.
Answer by Mubanga · Sep 11, 2016 at 04:30 PM
I did something similar in one of my games ones. You had the right idea but you have to use a Unlit shader in order to prevent the light from having any effect (I believe that is what you are trying to accomplish right?).
Answer by ahbreezy · Sep 11, 2016 at 09:51 PM
https://www.youtube.com/watch?v=9bhkH7mtFNE
I followed this tutorial for my 2d game and it's been working great.
Your answer
Follow this Question
Related Questions
How to hide game window but show sprite? 0 Answers
2d backgrounds - filling all screen sizes 1 Answer
2D Sprite Background Rendering 1 Answer
How can I stop my endless runners background sprites from falling out of sync? 1 Answer
How to feed background less image sequence to Unity for 2D game? 2 Answers