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 falconer · Aug 07, 2014 at 06:22 AM · resolutionbackground

Resolution independent background for a 2d game

Hello guys, I have an orthographic camera in the scene, I have a plane with a texture attached, I was struggling to find out how can I make the background of my game Resolution Independent. By resolution independent, I mean to say that the background should be the same no matter what mobile device the game is played on. The game will be built in Portrait mode. Any suggestions?

EDIT: This background is basically a car race track which will have 2d colliders to check if the car is hitting one of those colliders. I believe I cannot do this using a 2nd Camera, or can I?

Comment
Add comment · Show 2
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 robertbu · Aug 07, 2014 at 06:55 AM 0
Share

Your Edit helps, but a picture would be even better. Here are a few solutions.

  • For narrower aspects than the aspect designed for, adjust the orthographicSize of the camera so that the top and bottom of the screen are chopped off, but the image fills the screen.

  • Oversize the sides of the image so, if the aspect is wider, there will be material to show. A square image will cover all 'portrait' aspects.

  • Change the projection matrix of the camera to match the aspect (everything, not just the background, would be stretched or compressed.

  • Stretch/Shrink the width of the image to fit. Define the colldiers based on Viewport coordinates rather than world coordinates, and you might need to scale the colliders as well.

avatar image falconer · Aug 07, 2014 at 07:16 AM 0
Share

well, this sounds much more challenging than i thought it would be. Just to clear it up, I have a track. Zoo$$anonymous$$g out the camera will make the complete track visible. But I use the smoothfollow for camera to follow the car and only part of the track will be visible. I need this "part" of the track to be same in all screen resloutions.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Mayank Ghanshala · Aug 07, 2014 at 07:46 AM

I think Its not difficult task. All you have to scale your BG Image as the camera width and height. You can do it in your code.The problem is you can set height but not width in Editor as it always changes in every device. Here is a script to stretch bg as the resolution of any mob device in portrait mode.

 using UnityEngine;
 using System.Collections;
 public class BGScript : MonoBehaviour {
 SpriteRenderer sr;
 void Start () {
     sr = GetComponent<SpriteRenderer> ();
     float xmas = Screen.width*Camera.main.orthographicSize*2.0f /(Screen.height*1.0f);
     float yScale = Camera.main.orthographicSize*2.0f / sr.renderer.bounds.size.y;
     float xScale = 0;
     xScale = xmas / sr.renderer.bounds.size.x;
 transform.localScale = new Vector3 (xScale,yScale,1);
     }
     
 }


Add it to your background object in Editor.

Comment
Add comment · Show 3 · 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 falconer · Aug 07, 2014 at 09:12 AM 0
Share

I'll try it out. I had one more question though, what is the best image resolution I should use for better quality of the background?

avatar image Mayank Ghanshala · Aug 07, 2014 at 09:24 AM 0
Share

not sure but you can try with 960 * 540 and you can use format truecolor for better experience. Pack your images and using 2*power is the best option for resolution as they save memory and packing image save batching.

avatar image falconer · Aug 07, 2014 at 01:32 PM 0
Share

@$$anonymous$$ayank Ghanshala Resizing the image doesn't help bro. I have a race track as the background and colliders attached to the borders of the track. If I resize the image it will stretch/shrink the tracks, thereby misplacing the colliders compared to the track edges. Any other way?

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

22 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

Related Questions

Stretching Background sprite 4 Answers

Background and UI scalings are wrong 1 Answer

Unity 2D and Texture Memory. 1 Answer

How to set an objects position to the corner of the screen? (Unity 2D) 2 Answers

Making a point and click background. 0 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