• 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 luniac · Apr 28, 2014 at 02:47 AM · resolutionapp

help with making resolution independent app

Ok i truly can't find any concrete answers regarding this issue with making apps. Smartphones come with many screen sizes so there's gotta some way to code it so that it deals with them all.

In my particular 2D app, distance from the center to the edge of the screen matters, so I want to be able to have the game SCALE everything smaller or larger based on the current resolution, so that if in some DEFAULT(right?) set resolution its 5 meters from the center to the edge of the screen, the game will scale or shrink to maintain 5 METERS from the center to the edge of the screen.

I found code that can make the background sprite always scale to fit the screen width and screen height:

     function ResizeSpriteToScreen() {
     var sr = GetComponent(SpriteRenderer);
     if (sr == null) return;
      
     transform.localScale = Vector3(1,1,1);
      
     var width = sr.sprite.bounds.size.x;
     var height = sr.sprite.bounds.size.y;
      
     var worldScreenHeight = Camera.main.orthographicSize * 2.0;
     var worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
      
     transform.localScale.x = worldScreenWidth / width;
     transform.localScale.y = worldScreenHeight / height;
     }

Maybe I can adjust all the other sprite scales based on the background sprite scale set in that script? Like some kind of ratio? I'm really not sure how to best approach this. This is my first smartphone app. I hate coding this kind of utility stuff instead of focusing on making the game. Any help is really appreciated, thanks :)

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

1 Reply

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

Answer by SuperMasterBlasterLaser · Apr 28, 2014 at 04:40 AM

I have made similar question: Click here

The Idea is to multiplicate your camera to Matrix4x4

Comment
Add comment · Show 1 · 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 luniac · Apr 28, 2014 at 08:39 PM 0
Share

thank you thank you! I put this script on my camera:

 #pragma strict
 
 function Start() {
 
 Camera.main.projection$$anonymous$$atrix = $$anonymous$$atrix4x4.Ortho(-.5625f * 10,
     .5625f * 10, -10, 10, camera.nearClipPlane, camera.farClipPlane);
 
 }

.5625 = 9:16 aspect ratio(PORTRAIT $$anonymous$$ODE) 10 = my orthographic size

Now when i test in the game window, any 9:16 ratio resolution looks perfect and anything larger or smaller gets stretched appropriately.

I believe that is as good as it gets, since it maintains the same in game distance from the center of the screen to the edge. Smartphones use 9:16 anyways, so it should look good for the majority of devices.

And if I ever have a specific device resolution to publish to, all i have to change is the .5626 to whatever ratio the device has!

THAN$$anonymous$$S! :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Portrait Android app? 1 Answer

iTunes Connect - Does my app contain encryption? 2 Answers

iPhone exits app when game ends? 1 Answer

unity3d for apps, not games 2 Answers

Building an iphone game from a project made on windows? Xcode? 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