- Home /
Keeping screen width and scaling screen height for different screen resolutions
Hi guys,
I need my game to have a constant screen width for every mobile device in the market. For this I need to scale the screen height in order to keep the same screen width, even though the screen ratio varies.
Here you have an example:
You see the width is the same for both resolutions and only the screen height varies.
Any idea of how I can do this?
Thanks in advance!
EDIT:
Found this: http://gamedesigntheory.blogspot.ie/2010/09/controlling-aspect-ratio-in-unity.html
Is there a way to edit it to scale height instead of adding black frames? (keeping the width)
Up!
Answer by elhispano · Apr 08, 2014 at 09:10 AM
You need to change your camera orotographics size following the next formula:
ortographicSize = constantWidth / aspectratio * 2f;
Sorry, maybe the screenshots weren't much accurate. $$anonymous$$y camera is 3D.
try using Screen.SetResolution as seen in the documentation
function Start()
{
var resolutions : Resolution[] = Screen.resolutions;
// Print the resolutions
for (var res in resolutions) {
print(res.width + "x" + res.height);
}
// Switch to the lowest supported fullscreen resolution
Screen.SetResolution (resolutions[0].width, resolutions[0].height, true);
};
Answer by Patel-Sagar · Apr 08, 2014 at 10:11 AM
try this:
var verticalFOV : float =60;
var forcedAspectRatio: float = 0.75;
var manualNearClipPlane : float = 0.01;
var manualFarClipPlane : float = 1000;
function Update(){
camera.projectionMatrix = Matrix4x4.Perspective(verticalFOV, forcedAspectRatio, manualNearClipPlane, manualFarClipPlane);
}
Your answer
Follow this Question
Related Questions
Detect touch in screen at different resolutions 2 Answers
how to have an object positioned relative to the screen(like a button) 1 Answer
UI render doesn't sync with Camera movement 2 Answers
scaling (Resizing) orthographic camera in 2D mode 3 Answers
Why doesn't my players camera work and why does it spaz out randomly 1 Answer