- Home /
Keep Aspect ratio/Letterbox and maintain pixel perfection
Hello everyone, first time posting on this account but thought id see if you guys had any ideas on how to help with this issue im having since im relatively new to programming
wondered if anyone had any ideas how to letterbox the screen or maintain a consistent aspect ratio in unity while maintaining pixel perfection via an orthographic camera
so heres how i made achieved pixel perfection in unity, first i made all my sprites a power of two but most importantly i set the pixels per unity to a power of two, in this case 32x32
secondly i made sure my orthographic camera's size right using this script
Camera.main.orthographicSize = Screen.height / 32.0f/ 2.0f;
Now this alone makes everything work fine so long as all the sprites PPU are set to 32 and the sprite sheets them-self are a power of two, however before i did this i also had another script which made sure the screen maintained an aspect ratio of 16:9 at all times so if the resolution changed the edges of the screen weren't cut off, i used the following script which i found online
const float KEEP_ASPECT = 16/9f;
void Update () { float aspectRatio = Screen.width / ((float)Screen.height); float percentage = 1 - (aspectRatio / KEEP_ASPECT); GetComponent().rect = new Rect(0f, (percentage / 2), 1f, (1 - percentage)); }
Now i dont fully understand how this method of maintaining aspect ratio works but it does function properly, however if you have the two together then the pixels will still flicker and shift
So can anyone here help me understand this better, all i want to do is avoid cutting the edges of the screen off, is there a method where i can keep pixel perfection and letterbox the screen to fit, would love any advice
Your answer
Follow this Question
Related Questions
Same camera view on different resolutions 0 Answers
How to set constant orthographic viewport? 1 Answer
Why is the camera aspect ratio broken for the game tab? 0 Answers
Camera horizontal distortion? 1 Answer
What is the meaning of 1:1 in unity? 1 Answer