[Suggestion] To reduce memory usage of multiple CCSpriteBatchNode

Hey Guys,

I’ve register here for quite awhile but only manage to really look at it until few days ago. So I’ve a question here about how to do a task, if this function is not available, then I hope to make it a suggestion.

But first, let me state my problem.
CCSpriteBatchNode - This feature creates a more efficient way to reduce draw calls for OpenGL, but the problem is that, Sprite Sheet is a huge file and can take up alot of memory especially if there are any unused sprite, it will remain in memory togather with the other part since they are togather. Example for a game that can change equipment which has 100 different weapon, they all have to be loaded into a SpriteSheet togather with another 100 armor, this is a waste of space since the other weapon or armor are unused.

**CCSprite without Batch * - If the weapon are put into separated files, only 1 kind of weapon and 1 armor is loaded, this saves alot memory but create draw calls and frequent texture switching for OpenGL, since it cannot be loaded into the SpriteBatch.
My question is, is there any feature for me to “redefine”/“modify” a Sprite Sheet on runtime? For example, I first create a large Sprite Sheet using some texture packing tools that has 1 Background, 1 weapon, 1 armor, 1 character, 1 hair, and so on. Then later I will be able to draw the whole scene using the same sprite sheet. Even multiple draw calls does not require texture switching. Then when I wanted to change the armor for example, I will load that particular small file and replace the armor on the sprite sheet.
I understand that CCRenderTexture might be the option, but I would like to double confirm it and hope to get some suggestion on how should it be done so I do not need to modify the original cocos2d project.
Thanks.
**If there is a need for suggestion, I would be glad to give out my opinion to improve the framework. But at the sametime, I do not wish to interrupt the development because I understand Cocos2D-x is build base on Cocos2D-iphone and a constant framework is important between them. =D

The main reason for SpriteBatching is to reduce the number of times the GPU has to change from texture to texture to draw your game.
As a optimization you pack some sprites in the same texture to avoid some these texture rebindings.

If you’re packing the sprites in a way that you aren’t getting any better performance (or worse) is because you are not packing them correctly (to avoid bindings).

Deciding what sprites must go together is not a trivial task (as the grouping also affects their ordering) and it has different solutions for every case.

Modifing a spritesheet in runtime would get costy, having to update all the sprites that use the spritesheet, generate a new texture and plist with the info.

I think (i don’t know) that would get very slow to program and very slow to execute. I’d try to find the best grouping that I could and live with it.

Cheers!

Thanks Xavier for the reply. I do understand what your’re saying but thats not my problem, I do not have any performance issue, just want to bring memory consumption to its minimum. I would like to understand how to achieve it with Cocos2D-x in a standard manner. Sorry for not explaining properly, but I’ll try to explaining it better.

This is the initial sprite sheet on beginning of the game.

Before a game start, a user change weapon, which loads the weapon file and redraw it onto the weapon portion of that sprite sheet.

I hope this will make my question clearer.

Thanks.

I understood you :stuck_out_tongue:
As you don’t have any perfomance issue you can load files individually without any need of batching.
The goal of batching is to optimize gpu performance, normally at the cost of memory.

These images you showed me, explain perfectly what you want to accomplish, but I don’t think CCRenderTexture or any other class is prepared for that.

You should be able to use CCRenderTexture though; to do it you need the content of the original texture in the CCRenderTexture, so you can modify it later. I don’t recall there’s any method to load into a CCRenderTexture from a file.

Once you got that you can draw on it normally. You might have problems to erase what you draw without redrawing all the original content. Try different color blendings, if you cannot do it with any of them you’ll need a custom shader.

If you finally implement this i’d love to see how you did it :smiley:

Cheers!