- Home /
How do I make sure my game fits on all mobile platform screens?
Im building a game and in the game tab of unity I made sure its 320x480 as I was told is standard for mobile devices. My problem is that I am not sure if it will fit on all screen seeing as a tablet for example, is not the same size as a smart phone. Does anybody have any suggestions as to how to make sure it fits on all mobile platforms?
Indeed, exactly what you do depends on the game. With something like Bejeweled, for example, you might decide to make the "important" part an average aspect ratio like 2:3, and use fluff around the gameplay area to pad out the borders on either the sides or top/bottom, depending on taller or squatter screens. Then you have something like Jetpack Joyride, where you'd anchor the character to the right edge of the screen, which scrolls from right to left. You can't anchor to the left edge, because then people with wider screens would have an unfair advantage of having slightly more time to react to obstacles.
Exactly! It depends 100% on your game. I personally have only released my game on iOS. Because Apple only has two screen sizes, I didn't have to worry about GUI or aspect ratios. I just measure the exact resolution and set my HU elements to fit that resolution (real simple since there are only two resolutions, but now I here talk of bigger screens... haha ).
Well...there currently is 640x960 3.5" (the 4S is still relatively common), 640x1136 4", 768x1024 10" (iPad 2 also still relatively common), 1536x2048 10", 768x1024 8" (iPad $$anonymous$$i), 1536x2048 8", so...a bit more than 2 screen sizes. ;)
Haha yes I meant to say for iOS iPhone/iPods. The iPads, to my knowledge, have a separate App Store. They can still download from the iPhone App Store, but they have to upscale the game. To fix this Apple made a separate App Store for game built for the iPad. That is why iPhone/iPad apps typically have bester performance than the same apps built for android. Its because developers can build their apps specifically for a handful of available iOS devices, compared to the thousands of android devices. Anyone who has used an Android device has seen the "only supports these devices: " on the Goggle Play Store. There is just no way to account for all screen sizes, all different specs, and all different makers.
No, the store is mostly the same for all iOS devices. There was more separation originally, but now you typically build apps that run on both.
Answer by Eric5h5 · Mar 09, 2014 at 06:27 AM
320x480 is totally not standard for anything except old iPhones that aren't used much anymore. Don't hard-code for any particular resolution; anchor GUI elements to screen corners instead, and make sure the camera can handle multiple aspect ratios (4:3 though 16:9 at least, or 3:4 though 9:16 depending on screen orientation). Change the game view size and aspect ratio frequently while developing to make sure it continues to work on all screen sizes. Also make your GUI resolution-independent, so high-dpi screens don't get stuck with tiny GUI elements.
How can you anchor object which dont have rect transform? Im trying to animate UI elements, but the animations are lagging and it not smooth. The objects are not even UI, but thats just the only way I know how to make them fit on every screen, if they are on the hierarcy the animations are smooth but they cannot be positioned correctly
Answer by fifthknotch · Mar 09, 2014 at 06:39 AM
This is probably one of the most popular questions mobile developers ask yet impossible to answer because there exists no one, simple answer. There is no simple way to make your game fit on ALL screens. Period. Different methods of trying to include:
-making your camera view only set resolutions (very bad option because you lose all the excess screen) -using GUI to dynamically set your input/HUD elements during gameplay (this can be a bad option because Unity's GUI is very processor heavy and is not ideal for mobile devices) -manually checking for common aspect ratios and position/scale your input/HUD elements depending on those common aspect ratios
Also as far as 320x480 is concerned, that is a resolution. You are more interested in aspect ratios because resolution is continually increasing, but aspect ratios are staying relatively the same. For example. 320x480 is the aspect ratio 2/3. This happens to also be the aspect ratio of the iPhone 4s and before, even though the iPhone 4s's resolution is 640/960. 1080x1920 is 9/16, iPad's aspect ratio is 3/4. Screen aspect ratios vary, but screen resolutions vary so much more).
If you find an alternative GUI to use, such as NGUI, that is probably the best option. Otherwise using aspect ratios may take longer to setup, but also is a viable solution.
Answer by Alliballibaba · Feb 19, 2020 at 12:12 AM
SInce this is still relevant, I wrote a small script that blacks out anything outside of your preferred aspect ratio. Just put it on your camera. Might not be exactly what you're looking for, but it's a quick fix.
using UnityEngine;
public class FixCamera : MonoBehaviour
{
// change these numbers to your preferred apect ratio (9:16 in this case)
const int resolutionX = 9;
const int resolutionY = 16;
void Start()
{
float screenRatio = Screen.width*1f / Screen.height;
float bestRatio = resolutionX*1f / resolutionY;
if (screenRatio <= bestRatio)
{
GetComponent<Camera>().rect = new Rect(0,(1f- screenRatio / bestRatio)/2f, 1, screenRatio / bestRatio);
}else if(screenRatio > bestRatio)
{
GetComponent<Camera>().rect = new Rect((1f- bestRatio / screenRatio) /2f, 0, bestRatio / screenRatio, 1);
}
}
}