0
\$\begingroup\$

I've just started developing my first game with android using SurfaceView. I scale my bitmaps to support different screen sizes. But I don't know it's better to do the scaling when loading the bitmaps or when drawing them to canvas using Matrix. I guess the first one would occupy more memory but it's better in performance. But I don't know how really things work here so any suggestion from experts would be appreciated.

\$\endgroup\$
  • 2
    \$\begingroup\$ What where the results of your performance tests which you surely did before opening this question? \$\endgroup\$ – Philipp Aug 13 '14 at 9:11
  • \$\begingroup\$ Base on my test pre scaling result in a better FPS. But I don't know is it a good practice or not? @Philipp \$\endgroup\$ – Ali Aug 13 '14 at 9:14
1
\$\begingroup\$

Scaling of textures when rendering is generally not very performance intensive - it can sometimes even be faster to render small textures that are scaled up (usually when there are lots of textures and they need to be swapped from ram to vram). Of course, using small textures comes at the cost of quality.

It is generally best to avoid doing scaling yourself during runtime. If you want better quality for the textures then create multiple sets of textures (at varying resolutions) and determine the appropriate textures to load based on device resolution.

\$\endgroup\$
1
\$\begingroup\$

Android has special folders for this occasion, folders like drawable-ldpi and drawable-mdpi are for screens with different densities (ldpi = low density, mdpi = medium density).

You can do the same with screen sizes: drawable-normal or drawable-normal-ldpi

The plus side using this method is that when a user installs your app, only the images that are going to be used will be installed (since screen size or density can't physically change). This saves both memory and cpu.

For more info about folder names and qualifiers: Android - Supporting Multiple Screens

\$\endgroup\$
0
\$\begingroup\$

be carefull:

1. if you scale all image according to screen size first and then draw on canvas

---> loading these bitmaps allocate memory and cause Grow Heap (bigger screen size = more memory allocation)

2. if you load all image without scale and scale framebuffer on draw

---> it make your FPS (frame per second) reduce and your game flickering (bigger screen size = more flicker)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.