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 RossoXIII · Mar 05, 2013 at 10:46 AM · android2dresolutionorthographicscreen size

The infuriating Orthographic camera Vs Android Resolution.

I still haven't been able to find the settings for my game to fit the width of an Android screen. I keep reading about orthographic sizes being half of the window dimension of the screen height, but in android there is no way to control the screen dimension. The system upscales/downscales everything as it sees fit.

I am making a 2D Game using the lowest common ratio denominator at 1.5 portraid (iphone), assets at 640x960 resolution. With an Orthographic size set to 1.5, everything runs pixel perfect in iPhone.

So I thought I would only need to change the orthosize of the camera in android to fit different resolutions. I would find the device width, calculate the necessary height the screen would need to have to mantain the 1.5 ratio and then use the screen height to calculate the value of the orthoSize camera. This way the screen would perfectly fit the width of the screen with top bars at the top and bottom if necessary.

But it doesn't work that way.

Somehow Android doesn't respect that, the only device that seems to respect those definitions is the Galaxy Nexus. Using a calculated 1.68 ortho size, the display shows an "almost" perfect image, i say perfect because they still have a 5 pixel border on the sides. But i can live with that. However, if I set the app to display the android top status bar it rescales the app... and those 5 pixels on each side become 10...

So now I am sure the camera is rescaling the imagem properly, but android is somehow rescaling the game view.

In other devices, witch have the same screen resolution (Xperia S comes to mind) it simply doesn't behave properly. The ortho camera size is calculated ao 1.68 but android simply displays something else.

This is driving me mad. I can't see a solution to this unless there is a way to set a flag in the app that tells to android NOT to do any system rescaling. But i have searched and searched and can't find anything on that regard.

Maybe I am missing some obvious solution here?

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 MalachiteBR · Feb 11, 2015 at 02:04 PM 0
Share

Did you get any lucky with this problem?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by RossoXIII · Feb 13, 2015 at 01:46 AM

Yes. The screen size must be calculated using the height value and not the width. Then you find the correaltion between both and calculate the orth value.

Just make a perfect scene fitting the view on the editor and add this script to your camera.

 #pragma strict
 
 var mainCamera: GameObject;
 var pixelHeight : float =0.0;
 var newOrthoSize : float =0.0;
 var equivalencia : float = 0.0;
     
 function Start () {
     
     equivalencia = 640*1.5/Screen.width; //ipad 768*1.5 //telefone 640*1.5
 
 #if UNITY_IPHONE
     if( iPhone.generation == iPhoneGeneration.iPad1Gen ||
         iPhone.generation == iPhoneGeneration.iPad2Gen ||
         iPhone.generation == iPhoneGeneration.iPad3Gen ||
         iPhone.generation == iPhoneGeneration.iPad4Gen ||
         iPhone.generation == iPhoneGeneration.iPadMini1Gen ||
         iPhone.generation == iPhoneGeneration.iPadUnknown
         )
         equivalencia = 768*1.5/Screen.width;
 #endif
         
     pixelHeight = camera.pixelHeight;
     newOrthoSize = pixelHeight / 960 * equivalencia; // ipad 1024 //telefone 960*
                     
     if (camera)    {
         mainCamera.GetComponent(Camera).orthographicSize = newOrthoSize;
     
     }
 
 }

Comment
Add comment · Show 2 · 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 MalachiteBR · Feb 16, 2015 at 01:21 AM 0
Share

Ill try that later. I manage to do what I wanted just by setting up the aspect ratio of the camera to 16:9, it worked on every phone I have. Ill try on more phones and your trick aswell. Thanks!

avatar image meat5000 ♦ · Feb 16, 2015 at 01:32 AM 0
Share

You'll notice that Unity likes to adjust the viewport rather than anything else in order to prevent crushing or stretching of the game world. This is most apparent at different aspect ratios.

This is $$anonymous$$d, leaving out any screen calculations for your game will give the most faithful reproduction of the world itself as it wont be affected by things like status bar. As soon as things become dependant on height and width is when things start breaking.

avatar image
0

Answer by MalachiteBR · Mar 11, 2015 at 02:31 PM

I solved this problem setting the aspect ration to 1.77 (16:9), so if somebody have a different aspect will see the same image but some distortion.

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

11 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

Related Questions

Android 2D game multi-resolution 0 Answers

Game looks different on device compared to Game View 0 Answers

Mobile Game Different Screen Size Issue 2 Answers

Resolution for assets on Android 1 Answer

camera and screen is much farther out on android build? 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