cocos2d-x 异步加载plist,png等文件

前端之家收集整理的这篇文章主要介绍了cocos2d-x 异步加载plist,png等文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.png的异步加载

?

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



2.plist和png一起的打包资源

废话不多,直接上方法,没有加载plist的api,我们使用如1的方法加载png,然后在回调函数中加载plist。

?

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



注意回调函数的参数,这是plist异步加载的关键,形参是png纹理。

?

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后缀的动画文件

?

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 ;
}
原文链接:https://www.f2er.com/cocos2dx/343649.html

猜你在找的Cocos2d-x相关文章