UI takes up too much memory

We are developing iPhone games. We find that a UI with 10 pictures of 480 by 320 pixel and 34 pictures of 128 by 128 pixel takes up too much memory and besides, when music is added, it will automatically exit the play. Anyone can help solve these problems? Many thanks.

You might have to change the import settings of those 480x320 images.

Non-square and non-power-of-two-sized images can't be compressed, so a 480x320 image will be in RGB 24bit or (RGBA 32bit) and will as such have around 600 KB.

If you now turn of "Generate Mip Maps", set Non Power of 2 sizes to "scale to nearest" (or "scale to larger") and the Texture Format to "RGB Compressed PRVTC 4 bit", the image should have around 128 KB, almost 1/5 the size.

Of course you can still display it as 480x320 - yes it might look a little bit more blurry, but it's not all too bad. This is the approach I used for the menus in Age of Curling

If you need pixel perfect 320*480 images for BG art, etc, I recommend drawing your images that size and pasting them into a 512x512 image with a black background, that way you can compress the images AND have a pixel accurate image (no blurriness).

Another thing to do is use GUITextures/Text for your UI, it's more work on your end but runs much faster on the iPhone. Good luck.

We had the same problem with full-screen images taking up far too much memory. We tried the above mentioned and to be frank, GUI elements typically just do not look good compressed.

What we ended up doing was arbitrarily loading and unloading the images as we needed them.

For example:

Our game had an omni-present HUD which was the full 480x320. We also had win/lose scenario screens and a pause screen which lead to an options menu.

Now, a user may play the level and never pause or bring up the in game options. A user can only win OR lose so to have all of these stored in memory is inefficient.

So we utilized Resources.Load to load in everything as we needed it and destroyed it once we closed out of the screen. To use garbage collection we simply just set the reference to the variable to a new GUITexture (not null).

Hope that helps!

Well the GUI is slow with too any images on the iPhone.

You could use the SpriteManager instead to reduce the number of drawcalls.

SpriteManager