I searched but i didn't found the answer. Before 4.3 update I used Andengine to make games, and their handling resolutions was simple. I set resolution 480x800, make the game for 480x800 screen, and andengine does scaling based on ratio (eg 4:3, 16:9). Here in unity I can't set resolution, and scaling is auto (yes i can set camera.aspect = 4f/3f). If I make new scene, set 480x800 image in scene and run it (to my android phone, it has 480x800 res), I get: http://i.imgur.com/bpTdRVE.png What should I do?
I've hit the same wall. I'm using libGDX right now and once I put in 480x800 the game will always scale to fit the device (for better or worse). With Unity I can get my game to fit nicely in a 480x800 screen, but any larger resolutions just add extra space like your image.
What's the size of your orthographic camera? Try setting it to 4 (Target Screen Height / 2 / Pixels to Units Ratio).
Hi bryantdrewjones I have it set to 4 at the moment and that works fine for 480x800. The problem is when I then put it on something like a Nexus4 which has a resolution of 768x1280 - I change the orth size to 6.4 but instead of the game stretching to fill the screen I just get extra blank space like skakac.33. From what I can tell, this might just be how Unity works since it's running on a 3D engine? It only understands aspect ratios, not per-pixel scaling?
Im developing my game with 320*480 as target resolution. For this i set up my camera size as 15 because i want 32 pixels to be 1 unit(480/32=15). The size mainly represents the height variable. To make this fill all screens properly(filling it completely) i calculated the height that fits my desired screen width. Basically: float desiredHeight=(targetHeight/targetWidth)*Screen.Width. Screen.SetResolution(Screen.Width, (int)desiredHeight,true); There might be a better solution which i havent found yet, but for now this fits my use case and works well on several screen sizes. Maybe this approach helps you to.
If you purchase this Unity extension (called 2D Toolkit), it will automatically resize your game for different screen resolutions... http://u3d.as/content/unikron-software-ltd/2d-toolkit/1Wi
Ahh, if your assets are designed for 480 x 800, you should keep your orthographic size at 4 regardless of the actual screen height of the device. I'm guessing you have a script that changes like orthographic size at runtime depending on the device's resolution? Locking the size at 4 should keep the game looking consistent across all possible resolutions.
You're a champion! That seems to have fixed it for me! Skakac does this work for you too? So if I understand correctly, the size of the orthographic camera should stay the same size as my asset scale (4), and because my assets are not actually changing in size neither should my ortho camera. But I increase or decrease the resolution of the screen it will still always gets constrained to the size of my orthographic camera, giving the impression of it scaling up or down. Is that...right? :???:
Yes, exactly It's confusing stuff, especially if you're used to working with pixels instead of Unity's arbitrary world units
I've been stuck with the same problem, I believe, and the solution does not seem to work correctly for me. It seems to work to bind the top and bottom of my asset (a 640x960 png) to whatever resolution I'm in, which is okay most of the time. But if the width of the device becomes too narrow than the sides are cut off. For instance, 800x480 is good: http://imgur.com/Y055j5Y .. But if I switch to 480x800: http://imgur.com/vyzpCVS ..you'll see the top and bottom are aligned with the edge of the screen at the cost of the edges of my gameboard. In this case I would like the camera to line up with the left and right side of the board, even though it will add some extra space above and below the image. In this case I can change my camera size to ~550 and it will fit perfectly around the image. I'm just not sure where this 550 comes from or how I should calculate it. I would think it a pretty common request to have a static camera that would fit a game board as tight to the edges as possible, though I cannot seem to find a known method. Any help is appreciated.
the camera size mainly represents the height and doesnt factor the width as consistent, you will need to do some calculations to make it fit your entire screen. might wanna try my solution i posted earlier in this topic.
Thanks Mogitu. After taking a look at your solution, I realized it wouldn't quite work for me (you seem to be setting the resolution, which I have no control over on a mobile device). But it did get me thinking about the relationship between the width and height, and how I could use that to determine the size of my camera and I believe I have come up with a solution. Because my target resolution is 640x960 (and my pixels to units ratio is 1), I determined my "desired ratio" of width to height by dividing 640 by 960 (.666). Now when the game starts up the first thing I do on the camera is determine the current screen's ratio of width to height. If the current ratio is GREATER than .666 then we will have extra space to the left and right of the game board, which is handled perfectly by our current camera with a size of 480 (Target Screen Height / 2 / Pixels to Units Ratio). Now if the current ratio is LESS than .666, then our screen resolution is too narrow width-wise and the left and right of our board will be cut off. To fix this we need to zoom out on the camera, AKA increase the size of the camera to include some extra space above and below our game board so that our width will fit in frame. To determine how much we needed to increase the size, I simply determined how much our current ratio was off of our desired ratio, and scaled the camera size by that amount: Camera.main.orthographicSize = (Target Screen Height / 2 / Pixels to Units Ratio) * (desiredRatio / currentRatio) Here is the script I attached to the camera to make this happen: Code (csharp): using UnityEngine; using System.Collections; public class CameraSetup : MonoBehaviour { // Use this for initialization void Start () { float TARGET_WIDTH = 640.0f; float TARGET_HEIGHT = 960.0f; int PIXELS_TO_UNITS = 1; // 1:1 ratio of pixels to units float desiredRatio = TARGET_WIDTH / TARGET_HEIGHT; float currentRatio = (float)Screen.width/(float)Screen.height; if(currentRatio >= desiredRatio) { // Our resolution has plenty of width, so we just need to use the height to determine the camera size Camera.main.orthographicSize = TARGET_HEIGHT / 2 / PIXELS_TO_UNITS; } else { // Our camera needs to zoom out further than just fitting in the height of the image. // Determine how much bigger it needs to be, then apply that to our original algorithm. float differenceInSize = desiredRatio / currentRatio; Camera.main.orthographicSize = TARGET_HEIGHT / 2 / PIXELS_TO_UNITS * differenceInSize; } } // Update is called once per frame void Update () { } } This seems to work to fit my game board to the contents of any resolution without cutting off anything vertically or horizontally. Thanks for the help!
Ah, cool you got it to work like that! Though i use my solution for mobile devices, which works pretty good so far. But i see now that it doesnt fit your use case. My solution will stretch the image just for the sake of filling the entire screen(no extra space horizontall/vertically).
I was looking for a solution to this problem too, I think that your code made possible for me to solve my issue. Would you mind if I use it for the release version of my game? I will put your name in the credits if you want.