Ignoring screen densities in my first game

After some headaches, I decided to use the ostrich algorithm to face the problem of different screen densities.

The root of the problem, as mentioned earlier, was that supporting different densities “the android way” meant to have different image resolutions for each density. There are, at least, two ways of doing this:

  1. Provide just one set of images in the drawable directory. 
    • Pros: This way, you work less, and the app will be smaller also. Android will scale these drawables up or down automatically, on load, to support -hdpi and -ldpi devices respectively.
    • Cons: The android scaling algorithm can cause some trouble when you have references to image pixels (even if they are relative, because of resampling).
  2. Provide one set of images for each density.
    • Pros: You control exactly each single pixel of each single image, allowing exact pixel references.
    • Cons: You have to work a lot more, the app size increases a lot, and you will need a set of pixel references for each set of images.

To avoid all these problems, I only have one set of images, that I place in the drawable directory. I load these images using something like this:

{
  BitmapFactory.Options opts = new BitmapFactory.Options();
  opts.inScaled = false;
  BitmapFactory.decodeResource(resources, id, opts);
}

When disabling the inScaled option, all the graphics will have the original resolution on every device. This have a direct impact, if your game is designed to fit in the screen, when you test it on another device with a smaller screen, it won’t fit, and on bigger screens, it won’t use the whole screen.

Thus, I redesigned the game just a little to use a very handy tool that will also allow to create more complex levels: the scroll!

Having scroll, it doesn’t matter if the game don’t fit in the player screen. The game area can be moved… It still leaves the problem of under-used screens, but I won’t bother, as the game will have several levels with different game area sizes, and a lot of them won’t even fit in the nexus one super-screen 🙂

That being said, I will actually have some graphics that will scale on different screen densities, like for example the applicacion logo, or the HUD elements, because I want them to always use the same percentage of screen.

Just an ending advice: If you are using the android Canvas, test your application on the three densities, and even on rare screen sizes. This is very easy with the help of the emulator, and you will discover exciting behaviors…

Anuncios

Acerca de Rubén L.

Software Engineer
Esta entrada fue publicada en android, English y etiquetada , . Guarda el enlace permanente.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s