Search Unity

Force Screen Resolution 480x320?

Discussion in 'Android' started by akasurreal, Oct 1, 2010.

  1. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    We have developed multiple games for iPhone using a 480x320 resolution. They are 2D games using an orthographic camera and use exact coordinates for many things. If I run the game in Editor using the "HTCLegend Wide" option, it runs and looks perfectly. Any other screen size and everything is wrong. When I compile to Nexus One, of course its all wrong as well due to its higher resolution. Things out of place, touch events off, etc.

    iPhone4 and iPad deal with this by automatically scaling the app, and I would like to do the same with Android but don't see how.

    I read that there is a way for the Android to automatically scale apps running at lower resolutions but I can't seem to find a way to make that work with Unity. I read in Android documentation something about "<supports-screens>" in the manifest XML. I found a manifest xml that Unity uses is in a Temp\StagingArea folder of my project but if I change the settings they are always overwritten on each new build so I can't test that.

    There must be a simple way to accomplish what I am doing here? Seems like this would be a common need for anyone porting 2D iPhone games to Android.

    Thanks for any help!
    Michael
     
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    You need to make your UI resolution independent. There is no way to change screen resolution (except rendering offscreen and blitting it upscaled, but that seems like a really poor choice). The manifest can be overridden by placing the new AndroidManifest.xml in the Plugins folder, but that will get you nowhere in terms of forcing resolution; <support-screens> is for applications that use the Android GUI elements. And it doesn't control the resolution but instead whether your application can handle the resolution or not. As Unity is rendered completely through OpenGL <support-screens> will have no effect on your problem.
     
  3. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    So there is no way for Unity to specify a singular resolution/density, hence forcing the Android OS to scale the app on its own? Besides this causing a huge amount of work for us, there is a large performance hit being forced to scale our game using Unity. I have already run some initial tests and our game runs worse on the Nexus One than on a iPhone 3G.
     
  4. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Success!!! I decided to try modifying the AndroidManifest.xml in the plugins folder anyway to:

    <supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="false" android:anyDensity="false" />

    This forced the phone to scale it for me, and the performance is much better!!! It also saves me countless amount of work. Not sure why you didn't think that would work, but I highly recommend this to anyone that is in the same situation as me. Thank you for letting me know to put that file in the plugins folder.
     
    Krish-Vikram likes this.
  5. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Because it will not guarantee 480x320. If you for example run it on a MotoDroid you will get w=569 h=320. If you run it on a Tegra Tablet you will get a 480x320 will a huge border around it.

    So, I still recommend to make the UI resolution independent.
     
  6. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    I see but, even if we have to account for various other medium sizes, it still is having the device do the scaling instead of Unity which results in much higher performance.
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Unity does not do scaling, it really renders at the real size.
     
  8. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Well whatever you want to call it. When I move my camera so that my game takes up the full screen on the Nexus One, I get <30 FPS, if I tell the phone to scale the app, I get 50+ FPS and looks identical.
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    It has nothing to do with calling.

    If its scaled by the device, then unity renders effectively only 480x320 pixels, thats the max quality you can get etc. Thats then stretched up with all its consequences.

    but if it renders at native, then you have 800x480 pixels on current devices and accordingly more details you can add.
    Especially with finegrained text usage that can easily make a day - night difference


    its clear that rendering 800*480 pixels each frame costs significantly more power than rendering 480*320 pixels per frame (thats the very root behind the reason why ipad and iphone 4 etc perform often worse than 3GS devices on the iphone world, just to bring up an example where you might have read about it already)
     
    Last edited: Oct 2, 2010
  10. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Sure, but as I mentioned, this is a 2D game designed for 480x320 using SpriteManager sprite maps. Without creating all new higher resolution resources to match each devices native res, it will have to be stretched, and my point is, the performance is much better having the phone stretch it than Unity. Still looks very good, no worse than iPhone4 stretching iPhone3G apps for example.

    As a side note, it's worth it to us, to create new assets for iPhone 4 retina display because its only one resolution, but I can't really justify creating 20 new versions of every asset we have to look perfect on each possible display resolution of all the crazy amounts of Android phones. This would also make the package very large. If this was a 3D game, then I would fully agree with you on rendering to native size and would highly simplify things for us.
     
    Last edited: Oct 2, 2010
  11. eternalnoob

    eternalnoob

    Joined:
    Jan 24, 2010
    Posts:
    53
    akasurreal, slightly offtopic for this thread, but can I ask you how you handle the camera in your 2D game at 480x320? I assume you have a fixed orthographic camera, but how do you lock it off so that the camera view is the 1:1.5 aspect ratio?
    EN
     
  12. eternalnoob

    eternalnoob

    Joined:
    Jan 24, 2010
    Posts:
    53
    Never mind, the answer is to use camera.aspect - EN
     
  13. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Yes, but your original problem/question was not about performance; it was how your program (UI/Game) handled screen resolution, as seen below:
    I never suggested you would need to spend time on "creating all new higher resolution resources to match each devices native res", but you can't use hard-pixel values (0-480,0-320). You need to use normalized screen coordinates (0-1,0-1) instead.
     
  14. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Interesting, I never actually played with the aspect option.
     
  15. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Curious how you would do that, when dealing with fixed size bitmap sprites for everything?
     
  16. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    904
    Obviously, you would stop using "fixed size" sprites or anything else. You can use billboards with texture atlases in a real 3D space (even for a 2D game). Then almost all of the "scaling" is handled automatically for you. But there are other ways to skin this cat, too, and it's nothing new.
     
  17. eternalnoob

    eternalnoob

    Joined:
    Jan 24, 2010
    Posts:
    53
    Oh, so how were you ensuring the correct aspect ratio with the orthographic camera? camera.aspect was the only way I could find to make the orthographic camera rectangular rather than square. And I still don't know what the "size" option of the orthographic camera refers to.
    EN
     
  18. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    the orthographic size field refers to the size of the camera box in 3d unity. if you set it to the height of the screen, it will basically become a 1 pixel = 1 3d unit relationship
     
  19. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Ok, but then you lose the crispness of a 1:1 pixel bitmap 2D look for our game. I know Unity was not necessarily meant to be a 2D engine, but we were able to make it work very well. Android is being a problem only because it does not have any fixed size resolutions like the Apple platform.
     
  20. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    For 480x320, I just set the Main Camera in the editor to these settings:
    X: 240
    Y: 160
    Ortho Size: 160

    This gives a crisp 1:1 pixel for fixed size sprite graphics, on the iPhone at least.

    The problem I see with setting aspect size to 1.5, is that it seems to stretch to fit the view area when I choose phones that don't have a 1.5 aspect (800x480), hence losing its aspect ratio, which is odd since it would seem setting the aspect ratio was to avoid that problem to begin with. It maintains its aspect though if I leave that alone or ResetAspect.
     
  21. dapdap

    dapdap

    Joined:
    Oct 5, 2010
    Posts:
    15
    Hi,
    Just wondering if you're bringing out your Panda game for the Android?
    Looks great - can't wait to play it if you do.

    Also how are you getting on with setting the screen resolution at 480-320 and letting the phone to the scaling?
    Is that working out? Have you tested it on a few different phones?

    Also, do you have a setting for Far Clipping plane - or does it matter?

    Cheers
    D
     
  22. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Thanks, BowQuest: PandaMania is pretty much ready to go on Android, was just waiting to hear that Galaxy S phones were working well with Unity. I don't have one to test on. I might put it out this week saying that you must have 2.2 on a Galaxy S phone, as it sounds like that is fixing the issues based on other posts I have read here.

    Letting the phone do the scaling definitely has a large performance increase for our game. I still have to do some mouse coordinate translations as it scales different on different screen resolutions, but that wasn't too hard to implement luckily. The Moto Droid, for example, stretches a bit wide, but doesn't look bad to me.

    I don't know anything about Far Clipping, didn't mess with that.
     
  23. dapdap

    dapdap

    Joined:
    Oct 5, 2010
    Posts:
    15
    Thanks for your reply.
    Glad to hear PandaMania is getting released soon - look forward to seeing it on an Android.

    When you mention issues - have you actually been able to get it running well on the likes of a droid running 2.1?
    If not - what's the biggest problem?

    I've only got a Droid with 2.1 Will you be releasing a demo version - would be great to try it out.

    Cheers
     
  24. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Probably will do a Lite version, but not sure if I will do it right away. I don't know if there are 2.1 issues on Droid. I just know its a problem with Galaxy S phones.
     
  25. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    904
    There don't seem to be issues with 2.1 on Droid (that's one of our test devices, and we haven't heard reports from customers, either.) So far it's only the Samsungs that are having a problem that requires 2.2 to fix.
     
  26. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Thanks for the clarification. Have you noticed any performance differences between 2.1 and 2.2?
     
  27. CapnJ

    CapnJ

    Joined:
    Aug 6, 2009
    Posts:
    29
    Hrm, for some reason the .xml is not being overwritten on "build", any thoughts?
     
  28. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Not sure if this is your issue but starting with 3.1 the manifest needs to be in:
    \Plugins\Android
     
  29. CapnJ

    CapnJ

    Joined:
    Aug 6, 2009
    Posts:
    29
    Ahh, got it. I'll give it a try.

    Thanks!
     
  30. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    I noticed in a message from android Market (next market update) : "Market will support filtering based on screen sizes and densities, as well as on GL texture compression formats. Filtering is based on <compatible-screens> and <uses-gl-texture> elements in an app’s manifest.".
    So could it become a problem to force scaling in the manifest ?
     
  31. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Yeah good question.
     
  32. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    If by "force scaling" you mean the <supports-screens> tag I don't think it will become a problem. Afaics Google is adding a new tag (<compatible-screens>), not altering the behavior of the existing <supports-screens> tag. You should even be able to combine them (like, supporting only high-res screens and at the same time blocking very low-res screens, to make sure your application is not installed on a device where your high-res UI doesn't scale. Or the other way around.)
     
  33. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    hey aka surreal.. so from what im understanding u change that line in the script and it will scale/ stretch for any phone size? genius! lol

    what if its a different ratio phone? like driodx compared to droid? does the game appear squashed or anything?
     
  34. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    That depends on your camera settings in your app. You can either maintain aspect ratio or stretch to screen. I actually have this as an option to stretch to screen and just toggle camera aspect to 1.5F or resetaspect(). FYI, on a tablet, much larger screen, it will not use the entire screen regardless using this trick, but thats probably for the best.
     
  35. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    hey to bring up an old thread, how do i change the camera settings to stretch or not stretch?
     
  36. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    There isn't a stretch option persay, but as I mentioned in my previous post, I was able to accomplish this by adjusting the aspect.

    Edit: there is also the other settings mentioned in the manifest that will allow the phone to scale if thats what you are looking for as well. In our app I did a combination of both for max performance since we didn't have higher quality assets anyways.
     
    Last edited: Jul 26, 2011
  37. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    well i was hoping for an easy solution to scale my GUI for different screen sizes, right now i can get the ratio and resolution to adjust like you mentioned, but it doesnt really effect the scale of my gui? and defaulting it to only load normal (480x320) just looks so much worse then the higher rez :(
     
  38. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    I see, I don't know if there is an 'easy' solution for scaling GUI on the fly for different resolutions if you are not having the device scale everything.
     
  39. pat_sommer

    pat_sommer

    Joined:
    Jun 28, 2010
    Posts:
    586
    so this solution is more for just objects are resolution? and not so much for gui?

    also i read somewhere that you received a boarder and if the app was set small enough it would not fill the screen? mine always seems to fill the screen, i wonder if im missing a step?

    also somewhere you said

    For 480x320, I just set the Main Camera in the editor to these settings:
    X: 240
    Y: 160
    Ortho Size: 160

    where are those x and y settings on the main camera?

    ive used unity for awhile now and this is making me feel like a total noob 8( lol
     
  40. akasurreal

    akasurreal

    Joined:
    Jul 17, 2009
    Posts:
    442
    Our projects are somewhat unique in that I am not using Unity in the way it was meant, you might say. Our projects are all 2D all using sprites, so there is no resolution independence that you would normally get by using 3D with textures. When moving to Android, we didn't want to make all new assets for every potential resolution so it made sense to just let the phone scale our 480x320 assets, and it also performed much better than doing the scaling from within Unity. I could then adjust the camera aspect to allow users to stretch to full screen or not from there. You could almost say everything in our project was "GUI" from your perspective.

    Those settings I mentioned on the Main Camera, are primarily relevant to a 2D engine that you want running at a fixed resolution, so I am not sure if you would want to use them. It's been a few months since I have been in Unity and don't have it handy at the moment, but I don't recall those settings hard to find on the main camera object.
     
    Last edited: Jul 27, 2011
  41. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    I guess you could use Screen.SetResolution to force a certain aspect ratio. Screen.SetResolution is also another way to accomplish the same thing as forcing the supported screen sizes in the manifest, but with much finer granularity.