Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kuos · Sep 11, 2016 at 02:15 AM · 2dspritebackground

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image metalted · Sep 11, 2016 at 09:15 AM 0
Share

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.

5 Replies

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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?).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

96 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges