Domanda

I am new to Cocos2D and CocosBuilder and I have a few questions regarding memory usages.

1) In CocosBuilder (or Cocos2D for that matter), if I use the same texture atlas (spritesheet) for ALL CCSprite objects in the same scene, would it save memory usage over separate texture for each sprite? To be precise, if I use one 4k*4k texture, will the game require memory for only one texture atlas (e.g. 4k * 4k * 32 bits)?

2) Can I use different texture modes for different sprites to save memory? For instance, using no-alpha mode for background image. In other words, can Cocos2D handle different texture modes in the same scene?

3) I have to implement a game with around 100 objects on a scene, three scenes in total. Right now, all objects on the same scene are using the same spritesheet. Still, the game crashes after switching between scenes for a couple of times. Each time I got mem-warning message. What would be the best way to resolve this issue? I tried to dump all those caches but still got the crash.

Thanks a lot!

È stato utile?

Soluzione

1) A texture is only loaded once, regardless of how many objects draw from it. Generally you don't save (much) memory from using a single texture, but you improve the loading time and rendering performance by drawing from as few texture atlases as possible rather than individual image file textures.

2) Yes. You can have, for example, RGB565 (no alpha), RGB5551 (bool alpha) or RGBA4444/RGBA8888 textures in the same scene, no problem.

3) Use Instruments. Check for leaks. If you're not using ARC, now is the time to switch. PS: don't purge caches, that's just wasting time AND memory because eventually textures need to be reloaded again. If you want to release a texture you're certain isn't in use at the time and not going to be used in the very near future, then uncache those textures and only those.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top