1、将图片通过TexturePacker打包成plist和png或.pvr.ccz(加密)文件
2、将需要加载的图片路径存入集合paths中
3、 for(int i=0; i<paths.size(); i++){
Director::getInstance()->getTextureCache()->addImageAsync(paths[i]+".png",[=](Texture2D*){
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(paths[i]+".plist");
_num++;
(_num== (paths.size()){
//loading finshed
}
});
}
4、从缓存图片中创建精灵
1)auto background = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->getTextureForKey(bgName));(切成多块的背景,没有打包)
2)auto sprite= Sprite::createWithSpriteFrameName(spriteName);
原文链接:https://www.f2er.com/cocos2dx/340209.html