1
votes

I'm developing app in cocos2d. Architecture of the app is pretty simple: Main Menu from which you can choose one from six submenus. After tap submenu starts. In main menu there are lot of textures in high resolution (for Retina iPads) after loading all textures it took approximately 408 MB (450MB max because I'm using removeUnusedTextures method) on Retina iPad.

And now I have two scenarios of optimising textures:

First: I'm loading minimal set of textures in the beginning of the app and when they needed other textures.

Drawback: when loading textures when app it freezes for moment to load data from disk. Can't load textures using GCD because not all cocos2d classes are thread safe and cocos is grumbling that all textures are not using the same id(CCSprite is not using the same texture id). (note: I'm loading *.pvr.ccz files with using CCSpriteBatchNode

Second: Loading all textures in the beginning of the scene.

Drawback: when switching between scenes for some time in memory there are resources from two scenes (menu and submenu especially when moving back from submenu to main menu). Because of that memory grows to 600MB and iOS kills app, crash, armageddon.

How to solve this issue? I tried to find something in Internet but without luck.

P.S I used TexturePacker to optimise texture as best as I can.

1

1 Answers

1
votes

To avoid the two-scenes-in-memory problem you can simply add an intermission (loading) scene in between that does nothing but display a "Loading" text or graphics. When you switch to the loading scene the old scene has time to deallocate before you load the next one.

You can also cut texture memory usage in half by reducing color depth from 32-bit to 16-bit. Particularly on Retina images the difference with proper color dithering is hard if not impossible to make out.

Also you can load textures in background using CCTextureCache's loadImageAsync method. But you'd still have to wait for the texture to be loaded before you can create a sprite using that texture, so you don't really win anything there.