- Home /
I have problems with the Camera.ortographic to adapt the view to screens with different resolutions.
I am developing a 2d game for android.
I have set up a Camera.ortographic that seems to fit only 16: 9 screens in the right way.
<
I am testing the app on a device with a 19,5 : 9 screen and the width of the view does not match the screen, it is wider than the screen, while in height there are never problems.
<
The screen is 2340x1080, while the height matches and is therefore 2340 the width of the view, instead it turns out to be 1316,25. (practically calculates the width automatically in 16: 9 based on the real height of the screen).
<
On the documentation, among other things, it is written that the width of the ortographic is calculated through the aspect (https://docs.unity3d.com/ScriptReference/Camera-orthographicSize.html) that I printed and it is correct.
<
I don't really know how to fix it.
<
I searched on google but found no useful solutions to this problem.
I would be really grateful for your help, thank you very much.
Answer by Dijjo10 · May 12, 2020 at 04:37 PM
Camera.orthographic works in a really strange way so to be clear I am attaching a photo.
<
<
public class Screenprop : MonoBehaviour
{
public static float realW;
public static float differenceW;
public void Awake()
{
realW = (2560f / RecogniseProportions()) * 9;
differenceW = (1440 - realW) / 2;
}
public float RecogniseProportions()
{
return Screen.height / (Screen.width / 9);
}
}
<
RecogniseProportions() in this case recognizes that the screen is 19.5 : 9, In realW there is 1181.54 which as in the photo is the width part of the view shown on the screen. While in differenceW there is the initial part of the view that is not shown on the screen.
<
So to position the objects you can rely on these 2 measures. For example if we want an object in position (0, 0) the coordinates will be (DifferenceW, 0), if we want it on the far right, the coordinates will be (RealW + DifferenceW, 0).
<
I hope I have been clear to others who may encounter this problem.
Answer by wasssim · May 07, 2020 at 11:52 AM
Hello,
I found a video that may help you to solve your problem:
https://www.youtube.com/watch?v=3xXlnSetHPM
I hope this will help you!
Thanks so much. The video didn't solve my problem but it gave me an idea that seems to have solved the problem.