cocos2d-x 異步加載plist,png等文件

1.png的異步加載

?html

1
2
Director::getInstance()->getTextureCache()->addImageAsync(reloadImages[curReloadImgNum],
                 CC_CALLBACK_1(LoadingScene::imageAsyncCallback, this ));



2.plist和png一塊兒的打包資源

廢話很少,直接上方法,沒有加載plist的api,咱們使用如1的方法加載png,而後在回調函數中加載plist。json

?api

1
2
Director::getInstance()->getTextureCache()->addImageAsync(reloadPlists[curReloadPlistNum]+ "png" ,
                 CC_CALLBACK_1(LoadingScene::plistImageAsyncCallback, this ));



注意回調函數的參數,這是plist異步加載的關鍵,形參是png紋理。app

?異步

1
2
3
4
5
6
void LoadingScene::plistImageAsyncCallback(cocos2d::Texture2D* texture)
{
     SpriteFrameCache::getInstance()->addSpriteFramesWithFile(reloadPlists[curReloadPlistNum].append( "plist" ), texture);
     curReloadPlistNum++;
     loading = true ;
}



3.plist和pvr.ccz一塊兒的打包資源

相似2的方法。函數

?動畫

1
2
3
4
5
6
7
8
Director::getInstance()->getTextureCache()->addImageAsync(reloadPvrPlists[curReloadPvrPlistNum] + "pvr.ccz" ,
                 CC_CALLBACK_1(LoadingScene::pvrPlistImageAsyncCallback, this ));
void LoadingScene::pvrPlistImageAsyncCallback(cocos2d::Texture2D* texture)
{
     SpriteFrameCache::getInstance()->addSpriteFramesWithFile(reloadPvrPlists[curReloadPvrPlistNum].append( "plist" ), texture);
     curReloadPvrPlistNum++;
     loading = true ;
}

4.CocosStudio導出的.ExportJson後綴的動畫文件

?this

1
2
3
4
5
6
7
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync(reloadExportJsons[curReloadExportJsonNum],
                 this , schedule_selector(LoadingScene::jsonAsyncCallback));
void LoadingScene::jsonAsyncCallback( float f)
{
     curReloadExportJsonNum++;
     loading = true ;
}
相關文章
相關標籤/搜索