Multiple screen resolutions/aspect ratios (games)
Asked Answered
T

6

44

EDIT: Thanks for all your answers and comments. After thinking about it i would rephrase the core of the question to: "How to determine and limit the minimum resolution/ratio my game is able to run on". Because imo either the game becomes unplayable on the smallest screen/ratio (lack of detail) or supporting even the smallest screen/ratio degrades the experience for all the others significantly. Besides we do not even know what the smallest resolution is or can restrict it in any way other than disabling ldpi... which still doesn't tell us about the smallest mdpi. After all i'm not thinking about how to create a good result but about how to create a perfect result ;). Guess it's not possible (yet?).

Note: This is purely about phones not tablets Also this question is not that relevant for applications as it is for games which don't use the Android layout system.

I always found the definitions of which resolutions to expect somewhat vague. I am aware of the list in the docs.

Now my first question is if this list is complete or in other words are manufacturer allowed to use other reolutions or aspect ratios. My current approach is to view this list in terms of aspect ratios which looks something like that (Not sure if it's exact but you get the idea):

  • ldpi: smallest aspect ratio 4:3
  • mdpi: smallest aspect ratio 3:2
  • hdpi: biggest aspect ratio 16:9

4:3 3:2 16:9

So if i want to cover a range of devices i figure out what my smallest and my biggest aspect ratios are and design the layout for the smallest while making it automatically grow to the biggest. For example if i want to support all densities i design the screens for 4:3 and make it grow to 16:9. In case i remove ldpi support i would design for 3:2. Of course this assumes there will never be an mdpi device with an aspect ratio of 4:3 which brings us back to my first question.

My preferred solution would be to indicate on the Android Market which aspect ratios my application can handle but that doesn't seem possible so far.

Does anyone have a better approach? (Keeping in mind that it's for games on phones only)

Tybie answered 15/8, 2011 at 2:44 Comment(7)
So how will the screen ratio affect the layout? Is it merely the size of images and components, or will you have a completely different layout for wider phones than for shorter phones?Gasp
As you can see from the wikipedia images the screen ratio makes the screen space only wider. I don't create multiple layouts, instead i make sure everything fits on the smallest and after that i implement some stepless growing from smallest to biggest... but in OpenGL of course... similar to the android:weight stuff.Tybie
Got it. I was thinking that if you were implementing this using Android Java, that you could simply get the screen ratio and scale all the images or objects based on that ratio.Gasp
I figured. I just wanted to be sure that I hadn't merely misinterpreted this line, and that you were interested in Java - and that this misunderstanding was a reason why nobody has yet provided an answer.Gasp
Actually it's implemented in Java (libgdx - libgdx.badlogicgames.com)Tybie
I wouldn't say it's opengl specific though... it's relevant for any game or graphics application that draws the whole screen based on custom routines even if it uses Canvas to do that. Also i'm getting good results right now... just wondering how to make it bullet-proof ;).Tybie
Also interested in this, from a game-dev perspective. It's not just a case of scaling the layouts, because we have multiple layers, some of which are fixed (i.e. overlaid HUD images, where horizontal stretching would look bad), and some of which naturally cope with aspect changes (e.g. a layer which is just a view onto a larger scene: changing the aspect ratio just changes the size of the viewport and allows more or less of the scene to be observed).Literary
T
4

I found a clear answer to the problem.

Minimum resolutions are undefined prior to 3.0. So for 3.0 and above it will be possible to choose a minimum resolution, design a game based on it and grow the layout dynamically on larger screens/ratios as mentioned by superM and others.

As you design your UI for different screen sizes, you'll discover that each design requires a minimum amount of space. So, each generalized screen size above has an associated minimum resolution that's defined by the system. These minimum sizes are in "dp" units—the same units you should use when defining your layouts—which allows the system to avoid worrying about changes in screen density.

  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp

Note: These minimum screen sizes were not as well defined prior to Android 3.0, so you may encounter some devices that are mis-classified between normal and large. These are also based on the physical resolution of the screen, so may vary across devices—for example a 1024x720 tablet with a system bar actually has a bit less space available to the application due to it being used by the system bar.

Source

Tybie answered 24/8, 2011 at 16:43 Comment(2)
Actually there many ways to handle those cases. You can apply many different options to deal with all the different aspect ratio and chose the right texture resolution of your assets. I've written an article that will help you : alexis.pautrot.com/dealing-with-different-screen-sizesNuisance
Alexis' link is dead.Myology
E
19

I can't directly answer your question, but i'd like to tell you my approach. I try not to use to use any numbers at all. Instead I try using paddings, margins and relative layouts so that my views look correctly on any phone. It also helps me to avoid creating view for different orientations.

Epithalamium answered 19/8, 2011 at 16:11 Comment(4)
+1 - This is the way to go. For example, game HUDs and on-screen controls can be placed relative to the edges of the screen.Rozamond
This approach just got one problem. What if you want to max out the available screen estate? Lets say you have a fixed size 2D playing field which does not scroll, scale or increase/decrease the level size based on phone... Tetris or PacMan for example. How do you determine your min/max values?Tybie
I do not determine them at all. I set height and width to fill_parent and that's all.Epithalamium
This is one way to go. But actually you have many options to deal with multiple screen sizes. I have written an article that may help you on that subject : alexis.pautrot.com/dealing-with-different-screen-sizesNuisance
G
4

As many people here mentioned before, my approach would also be making full use of the device-independent components, such as paddins, margins, and relativelayouts, combined with Device independet puxels.

To be quite frankly, and i hope i'm not the only one, but making full use of DIP's (device independet pixels) and relative layouting and such...has reduced my activity layout files to 1 per activity instead of 3 different kinds for HDPI, MDPI and LDPI.

in case you're really concerned about the aspect ratio, you can always call the display properties in pixels of the device, and make appropriate layout calculations based on those figures. You can call this at the very start of the onCreate method of your first activity.

Display display = getWindowManager().getDefaultDisplay(); int displayWidth = display.getWidth(); int displayHeight = display.getHeight();

this will give you the width and height values of your hardware siplay in pixels. In my opinion, the true reason why you would choose over 3 layout types is to make sure image resolution stays sharp enough.

With these numbers you can make some internal logic, wich calculates wich type of resolution images to load in certain widgets. Thus saving you the trouble of making 3 times the same layout....

maybe explained a little cryptic, but the main thing to overcome the various device resolutions is to work a lot with:

  • relativelayouts
  • Device independent Pixels

you can also define DIP's in the XML layout, so every component looks the same at every type of device.

maybe a stupid Example, but hey, it worked for me :-) here below i tried to get the text size on a textview to be relatively the same on all devices. You can call the 'TypedValue'class, and select from one of the many public variables offered there. As i wanted to make the TextView everywhere the same relative size, i used the code below :

someTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);

the number is to set how big the size in DIP's should be. TypedValue can be used in many widget or activity compoents that require an INT value for dimensional properties. Play with that and you will see it makes life a lot easier :-p

hope this answer helps a bit

Granlund answered 21/8, 2011 at 12:26 Comment(4)
Your approach works fine for applications but it does not work for most games. However due to the answers and comments i would rephrase the core of the question to: "How to determine and limit the minimum screen size my game is able to run on". Because imo either the game becomes unplayable on the smallest screen (lack of detail) or supporting even the smallest screen degrades the experience for all the others significantly. Besides we do not even know what the smallest resolution is or can restrict it in any way other than disabling ldpi... which still doesn't tell us about the smallest mdpi.Tybie
Well then, i guess it's all about making choices in life... OP: If i were you, i would simply develop my game to only allow devices within the range of MDPI, HDPI and XDPI (the large tablets)... and discard the small sized devices.... that will surely relieve you from headache. And lets be honest, a small device like the SonyEricsson Xperia 10 mini is not going to have the same processing muscles as a Game boy DS...Granlund
That what i do at the moment. But once a manufacturer creates a mdpi or hdpi device using 4:3 aspect ratio i'll get 1* ratings from those users. For now it works for all phones but it's not exactly what i consider high-quality if it can break any day. I think creating those groups (ldpi, mdpi...) was stupid in the first place at least for games.Tybie
for text size in must use sp and not dp I think?Dhole
T
4

I found a clear answer to the problem.

Minimum resolutions are undefined prior to 3.0. So for 3.0 and above it will be possible to choose a minimum resolution, design a game based on it and grow the layout dynamically on larger screens/ratios as mentioned by superM and others.

As you design your UI for different screen sizes, you'll discover that each design requires a minimum amount of space. So, each generalized screen size above has an associated minimum resolution that's defined by the system. These minimum sizes are in "dp" units—the same units you should use when defining your layouts—which allows the system to avoid worrying about changes in screen density.

  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp

Note: These minimum screen sizes were not as well defined prior to Android 3.0, so you may encounter some devices that are mis-classified between normal and large. These are also based on the physical resolution of the screen, so may vary across devices—for example a 1024x720 tablet with a system bar actually has a bit less space available to the application due to it being used by the system bar.

Source

Tybie answered 24/8, 2011 at 16:43 Comment(2)
Actually there many ways to handle those cases. You can apply many different options to deal with all the different aspect ratio and chose the right texture resolution of your assets. I've written an article that will help you : alexis.pautrot.com/dealing-with-different-screen-sizesNuisance
Alexis' link is dead.Myology
T
3

There is no exhaustive list of aspect ratios. Manufacturers can decide on whatever resolution they feel like. On top of that, aspect ratios don't match up with pixel density, so using ldpi/mdpi/hdpi to decide on aspect ratio is probably not a good idea.

Your strategy for dealing with this really depends on your game. Of course to a certain extent you should simply scale everything larger/smaller, but obviously the tricky parts are the edges which are different on different aspect ratios. Certain games (first person shooters, side-scrollers, tiled top-down games, etc.) you can just provide a different field of view without too much problem as long as you're not concerned about giving an advantage to certain devices, for others you might consider having a stretchable or tileable graphic for the background, and maintain the same effective (scaled) playing area.

Thermograph answered 19/8, 2011 at 18:28 Comment(4)
"On top of that, aspect ratios don't match up with pixel density, so using ldpi/mdpi/hdpi to decide on aspect ratio is probably not a good idea" - What do you mean by that?Tybie
Also my approach is based on taking the resolutions from the list and determining their aspect ratios which results in the "assumption" that only ldpi uses 4:3. At the moment this works fine but once somebody releases a 4:3 mdpi i would be screwed and can't even indicate on the market "up front" that it's incompatible. Scaling is out of questions since i don't want to screw up the experience of many for the experience of few and at the moment my approach covers about 99% of all phones.Tybie
Pretty much exactly what you're saying. Matching density with ratios is an assumption that only loosely fits. As an example, I believe both the Nexus One and the Motorola Droid are hdpi but the Nexus is 800x480 while the Droid is 854x480. Clearly not the same aspect ratio.Thermograph
800x480 is 15:9 while 854x480 is 16:9. However this is not much of a problem as long as you know what your min/max ratios are. If you support all from 3:2 to 16:9 than 15:9 is automatically covered by that since its just somewhere in-between and does only differ in width but not in height.Tybie
C
2

You can try asking in GameDev.stackexchange.com

Here is a similar problem to yours: building a game for different resoulution phones

Conyers answered 19/8, 2011 at 17:12 Comment(0)
J
0

You can limit what devices can see your game on marketplace based on screen resolution: http://developer.android.com/guide/appendix/market-filters.html

I've not delved into it fully but I can't see any mention of aspect ratio unfortunately so you might have to fill in all the ones you know will work.

Failing that, you can set a minimum resolution that you require for your graphics to look good and if you don't want to change the game for the smaller ratios, you can add black borders as they would do on console games. It's not recommended however, mobile screen space is precious enough so if you do chop the playing area with black bars, I would move your HUD into the black area so you are still using as much of the screen as possible.

There is more info on supporting screen sizes here: http://developer.android.com/guide/practices/screens_support.html

: D

Jannet answered 24/8, 2011 at 15:13 Comment(3)
I just found the answer. But it seems you are wrong. Minimum resolutions are undefined prior to 3.0 and i don't see any tools to limit based on resolutions.Tybie
I've not submitted anything on the marketplace so apologies if this was misleading. As you say, after 3.0 you can limit based on general sizes rather than specific resolutions. It seemed to point you in the right direction though so best of luck with the rest of the game.Jannet
Unfortunately it doesn't change much since 3.0 is a tablet-only system and probably won't be merged with the phone version of Android till 4.0.Tybie

© 2022 - 2024 — McMap. All rights reserved.