码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx3.4 分割plist图片

时间:2015-02-09 15:31:35      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:

如果想要修改一个plist文件新打包成plist,而此刻原来的小图都找不到了,那只能把plist分解了,代码如下:

void UiManage::DecodePlist(string imgPath,string plistPath)
{
    FileUtils *pFileUtil=FileUtils::getInstance();
    SpriteFrameCache *pFramChace=SpriteFrameCache::getInstance();
    pFramChace->addSpriteFramesWithFile(plistPath,imgPath);

    ValueMap plistDic=pFileUtil->getValueMapFromFile(plistPath);
    if (plistDic.find("frames")!=plistDic.end())
    {
        Point pos(0,0);

        ValueMap framesDic=plistDic["frames"].asValueMap();
        for (auto it=framesDic.begin();it!=framesDic.end();it++)
        {
            string imgName=it->first;
            string savePath="screenshot/"+imgName;
            //SpriteFrame *pFrame=pFramChace->getSpriteFrameByName(imgName);
            Sprite *pSpr=Sprite::createWithSpriteFrameName(imgName);
            if (pSpr)
            {
                Size imgSize=pSpr->getContentSize();
                RenderTexture *pRenderTexture=RenderTexture::create(imgSize.width,imgSize.height);


                pRenderTexture->begin();

                pRenderTexture->setAnchorPoint(pos);
                pSpr->setAnchorPoint(pos);
                pSpr->setPosition(pos);
                pSpr->visit();

                pRenderTexture->end();
                pRenderTexture->saveToFile(savePath,Image::Format::PNG);
                CCLOG("save img %s",imgName.c_str());

                //CC_SAFE_RELEASE(pRenderTexture);
                //CC_SAFE_RELEASE(pSpr);
                pFramChace->removeSpriteFrameByName(imgName);
            }

        }
    }
}

 

cocos2dx3.4 分割plist图片

标签:

原文地址:http://www.cnblogs.com/gamesky/p/4281440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!