Is it safe to use CCSpriteFrameCache to load texture in another thread ?

I faced with memory limitation. Thus my approach is to load and use some textures first, then some other textures which aren’t needed right now will be loaded just-in-time when I need it, but of course I have to clear all previous loaded textures first to make a room for it.

The point is that I need to do this pretty smooth. I think I use multi-threading.
So my question is “Is it safe to use CCSpriteFrameCache to load additional spritesheet in seperate thread?”.

I knew that cocos2d-x is not thread-safe, but my strategy is to use as minimum of cocos2d related classes in separate thread as much. When I finish loading, I will continue creating a new CCSprite or anything represents my objects in a main normal thread.

Okay I do some more researches, and I think I answer my own question.

In short, you can use CCTextureCache to load texture object (CCTexture2D) asynchronously then plug in that object into CCSpriteFrameCache in one of its method that accepts .plist file and CCTexture2D object.

You can find more information according to my answer on my own question on stackoverflow here http://stackoverflow.com/questions/13248873/how-can-i-load-a-texture-in-separate-thread-in-cocos2d-x/13249654#13249654.

1 Like

Wasin Thonkaew wrote:

Okay I do some more researches, and I think I answer my own question.
>
In short, you can use CCTextureCache to load texture object (CCTexture2D) asynchronously then plug in that object into CCSpriteFrameCache in one of its method that accepts .plist file and CCTexture2D object.
>
You can find more information according to my answer on my own question on stackoverflow here http://stackoverflow.com/questions/13248873/how-can-i-load-a-texture-in-separate-thread-in-cocos2d-x/13249654#13249654.

It seems can’t add sprite in another thread ,but I think it can load img in to CCTextureCache ,and set a flag,the main thread check the flag,when true ,use the img in CCTextureCache.
I’ll try tomorrow,lol