michael.yue
michael.yue

Reputation: 109

huge memory used when load Multiple animations and textures with Cocos2d, how to solve it

I am working on a gameplay which needs load 27 texture altas (each one 1024 * 1024) before enter the game scene

but sometimes my game crash because receiving memory warning

I know 27 texture altas will use: 4 * 27 * 1024 * 1024 = 108mb memory which is huge amount, but I really need to load them before entering game.

Is there anyway to solve my issue? Any ideas will be very appreciated!

BTW: I am using cocos2d 1.0.1

Upvotes: 1

Views: 440

Answers (2)

YvesLeBorg
YvesLeBorg

Reputation: 9079

Best suggestion is to review your design, and the 'need' for preloading all these textures. I tend to pre-load only the textures that are most frequently used (animations and static map objects).

For example, I have textures for animating walks on a map for 16 character classes. I regrouped the 'idle' animations in 4 textures, and preload these, because initially, when a soldier enters the scene, it idles. The moving animations are in separate textures that are loaded in real time, as a function of the direction of travel, for each character class in movement. When the characters stop walking (idle), i remove unused textures from the cache, as well as unused sprite frames.

Also: there are other avenues for memory management. You could use a 16 bit format for certain textures (RGB88888 is the default). You may gain by converting to compressed PVR format (once again this is lossy, but could be fine for some textures)

Look here and there to learn more about picture formats in coco, and the relationship to memory consumption (as well as load, rendering speeds). But once again, before you start optimizing, make certain you have no alternative to the pre-load all approach.

Upvotes: 2

Haroon
Haroon

Reputation: 695

use jpg instead of png it will make that non transparent you can make that transparent by alpha image of that image it will help you reducing size almost half of you are using now.

Upvotes: 0

Related Questions