拆分Cocos2D-Xplist中的所有图片另存为单张png
http://www.jb51.cc/article/p-nnaavlwz-bgx.html
该帖子使用 cocos2d-x 3.3 的版本 重新 编辑了一遍
{
RenderTexture* pScreen = RenderTexture::create(pSpriteFrame->getRect().size.width
,pSpriteFrame->getRect().size.height
,Texture2D::PixelFormat::RGBA8888);
//渲染纹理开始捕捉
pScreen->begin();
Sprite* pSprite = Sprite::createWithSpriteFrame(pSpriteFrame);
pSprite->setAnchorPoint(cocos2d::Vec2::ZERO);
//当前场景参与绘制
pSprite->visit();
//结束捕捉
pScreen->end();
//保存为png
pScreen->saveToFile(name,Image::Format::PNG);
}
//2.解析plist
void HelloWorld::decodePlist()
{
CCLOG("%s",FileUtils::getInstance()->getWritablePath().c_str());
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
pSpriteFrameCache->addSpriteFramesWithFile( "SDsprite_sheet.plist","SDsprite_sheet.png" );
//需要先把_spriteFrames 改成public,否则无法访问
Map<std::string,SpriteFrame*> pDic = pSpriteFrameCache->_spriteFrames;
CCLOG("[%s ]有 [%zd] 张图片","SDsprite_sheet.plist",pDic.size());
std::vector<std::string> iKeys = pDic.keys();
for(auto element = iKeys.begin() ; element != iKeys.end(); ++element)
{
std::string iK = std::string(element->c_str());
SpriteFrame* pFrame = (SpriteFrame*)pDic.at(iK);
saveFile(pFrame,iK);
}
}
原文链接:https://www.f2er.com/cocos2dx/344929.html