解决异步加载plist跟纹理!

研究的半死,就是搞不透批量异步加载plist,png资源。终于让我研究出来了!

vector paths1;//Armature动画的文件路径
vector paths2;//plist文件路径

int count;
int total;文件总数


void LoadingScene::startLoader()
{
 ArmatureDataManager* admanager=ArmatureDataManager::getInstance();
 int len=paths1.size();
 for (int i = len - 1; i >= 0 ; i--)
 {
 admanager->addArmatureFileInfoAsync(paths1*+".ExportJson",this,schedule_selector(LoadingScene::loadAnimationComplete));//异步加载Armature动画
 }


 len=paths2.size();
 for (int j = len - 1; j >= 0 ; j--)
 {
        TextureCache::getInstance()->addImageAsync(paths2+".png",CC_CALLBACK_1(LoadingScene::loadCallBack,this));//先异步加载纹理
 }
}


void LoadingScene::loadAnimationComplete(float time)
{
 count++;
 if (count>=total)
 {
 if (complete)
 {
 complete();
 }
 }
}
void LoadingScene::loadCallBack(cocos2d::Texture2D *texture)
{
 count++;
 if (count>=total)
 {
 if (complete)//加载结束后,在加载plist
 {
 int len=paths2.size();
 for (int i = len - 1; i >= 0 ; i--)
 {
 //注意,由于paths2+".png"已经被加载,因此再次在addSpriteFramesWithFile会直接从纹理缓冲中取
 SpriteFrameCache::getInstance()->addSpriteFramesWithFile(paths2*+".plist",paths2*+".png");
 }
 complete();
 }
 }
}


```




***

赞一个,异步加载解决画面没有动画相应的问题。