Load resources in background, especially sprite frames.

Hi, I want to load an image with many sprite frames. For the texture I can use CCSharedTextureCache::addImageAsync, no problem. The problem is when I call this method in game thread,

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistFileName.c_str(), imageFileName.c_str());

it feels pretty slow. I want to load resources in background thread, but the wiki says the autorelease pool is not thread safe. Is it okay if I load resources in another thread? Such as sprite textures, sprite frames,sfx and musics.

Thanks :slight_smile:

If you know the image file path ahead of time, can’t you just run addImageAsync function and then add the plist to the sprite frame cache in the callback function instead?

Yes I’ve already done that, but parsing the plist file is also a bit time consuming, resulting in a noticable lag. That’s why I’m wondering if it’s okay to add the sprite frames in the background thread.

Could it be that a large group of sprite frame texture slows down the loading time instead? The sprite sheet I mentioned has about 50 objects, and the texture is about 1.6mb. My friend said it’s better to put only animated frames into one sprite sheet, and other non-animated textures such as buttons and UI items in each own file. The resulting files would be human.png+human.plist, monster.png+monster.plist, button1.png, button2.png, box.png, etc.