Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Asdemt · May 29, 2014 at 12:56 PM · 2dbackgroundmovingclippingvertical

Vertically scrolling 2D background clips

I'm making a vertically scrolling 2d background that loops. Here's the code:

 using UnityEngine;
 using System.Collections;
 
 public class BackGround : MonoBehaviour {
 
     //the point the background goes back to start
     private float reset = 19.2f;
 
     //the point where the background goes after a reset
     private float startPoint = -19.2f;
 
     //the speed of movement
     private float speed;
 
     void Update () {
 
         //if the background is at reset point, move it to startPoint
         if(reset <= transform.position.y) {
             transform.position = (new Vector3(0, startPoint, 0));
         }
 
         //EnemySpawner.speedPlus is a static float
         speed = 0.05f + EnemySpawner.speedPlus;
 
         //Move the backgound up
         transform.position += new Vector3(0,speed,0);
 
     }
     
 }

The problem is that there is a space between the backgrounds where is nothing. Background 1 is set to (0,0,0) and background 2 is at (0,-19.2,0). -19.2 seems to be the right coordinate so that the background 2 is just right under the background 1 (they are the same picture).

![alt text][1]

As you can see in the image, there is a white line between the backgrounds. I want that line gone.

It's my first post here so pardon me if i did something wrong. Also feel free to ask anything. [1]: /storage/temp/27046-bug.png

bug.png (58.1 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Asdemt · May 30, 2014 at 06:00 PM

Managed to fix it with my own way as changing reset point didn't help and solution 2 was too time consuming. For anyone with the same problem i just made the background to go to the exact position of the lower backgrounds end.

 using UnityEngine;
 using System.Collections;
 
 public class BackGround : MonoBehaviour {
 
     //the point the background goes back to start
     private float reset = 19.2f;
 
     //the point where the background goes after a reset
     private float startPoint;
 
     //the speed of movement
     private float speed;
 
     public GameObject otherBackground;
     
 
     void Update () {
 
         SpriteRenderer sRenderer = otherBackground.GetComponent<SpriteRenderer>();
         startPoint = transform.position.y - sRenderer.bounds.size.y*2;
 
         //if the background is at reset point, move it to startPoint
         if(reset <= transform.position.y) {
             transform.position = (new Vector3(0, startPoint, 0));
         }
 
         //EnemySpawner.speedPlus is a static float
         speed = 0.05f + EnemySpawner.speedPlus;
 
         //Move the backgound up
         transform.position += new Vector3(0,speed,0);
 
     }
     
 }

Thanks for the support anyway.

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 jasonkutty · May 29, 2014 at 10:07 PM

It is probably because of the origin of the "reset point". Try moving the reset point a bit closer than before.

Solution : 2 Instead of moving backgrounds by repositioning, try Instantiating the backgrounds and have a constant scrolling of backgrounds. Destroy panes that go out of camera view to improve performance as well.

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

21 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

Related Questions

2D Infinite Vertical Background scrolling 0 Answers

I want my character to move up and down the y axis but pause its movement whenever I press mouseclick 0 Answers

How to create an infinite, non-moving background in a 2D game 1 Answer

Creating pixelperfect backgrounds for a 2d Game 2 Answers

Background Image in 2D 1 Answer


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