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 “” 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.
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; 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 will have no effect on your problem.
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.
Success!!! I decided to try modifying the AndroidManifest.xml in the plugins folder anyway to:
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.
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.
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.
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.
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 800480 pixels each frame costs significantly more power than rendering 480320 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)
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.
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
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.
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.
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
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
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.
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.