加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

拆分Cocos2D-Xplist中的所有图片另存为单张png

发布时间:2020-12-14 20:04:54 所属栏目:百科 来源:网络整理
导读:拆分Cocos2D-Xplist中的所有图片另存为单张png http://www.jb51.cc/article/p-nnaavlwz-bgx.html 该帖子使用 cocos2d-x 3.3 的版本 重新 编辑了一遍 //1.保存文件函数 void HelloWorld::saveFile(SpriteFrame* pSpriteFrame,std::string name) { RenderTextu

拆分Cocos2D-Xplist中的所有图片另存为单张png



http://www.52php.cn/article/p-nnaavlwz-bgx.html

该帖子使用 cocos2d-x 3.3 的版本 重新 编辑了一遍



//1.保存文件函数

void HelloWorld::saveFile(SpriteFrame* pSpriteFrame,std::string name)
{
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);

}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读