cocos2dx3.4 分割plist图片

如果想要修改一个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);
            }

        }
    }
}

 

posted @ 2015-02-09 14:10  冷夜 - 网游编程技术  阅读(3081)  评论(0编辑  收藏  举报