- Home /
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?
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;
}
}
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!
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.
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.
Your answer
Follow this Question
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