博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用Coco2dx提取plist中的图片
阅读量:4354 次
发布时间:2019-06-07

本文共 1252 字,大约阅读时间需要 4 分钟。

做一个Demo,需要利用序列帧图片,想到Cocos2dx能够解析plist文件获取打包后图片中的小图片,就想如果Cocos2dx能够提供保存精灵/纹理到文件中的方法,那么就可以将plist文件中的小图片提取出来。果不其然,RenderTexture类提供了saveToFile方法,用于将纹理保存到文件中,下面直接上代码以供以后参考

 

void GameScene::SaveFiles(){    //加载plist文件到缓存    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("fish.plist");    std::stringstream ss;    std::string filename;    //遍历序列帧图片    for (int i=0; i<10; i++)    {        ss.clear();        ss.str("");        ss << "fish_" << (i + 1) << ".png";        filename = ss.str();        //获取精灵        auto sprite = Sprite::createWithSpriteFrameName(filename);        sprite->setAnchorPoint(Vec2::ZERO);        float width = sprite->getContentSize().width;        float height = sprite->getContentSize().height;        //创建渲染纹理        auto render = RenderTexture::create(width, height, Texture2D::PixelFormat::RGBA8888);        render->setSprite(sprite);        //填充纹理        render->beginWithClear(0, 0, 0, 0);        sprite->visit();        render->end();        //文件被保存在类似于C:\Users\Administrator\AppData\Local\ProjectName的路径中        render->saveToFile(filename, Image::Format::PNG);    }    //从缓存移除plist文件    SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("fish.plist");}

 

转载于:https://www.cnblogs.com/aibox222/p/8716029.html

你可能感兴趣的文章
Android关于buildToolVersion与CompileSdkVersion的区别
查看>>
袋鼠云日志,日志分析没那么容易
查看>>
缓存穿透 缓存雪崩 缓存并发
查看>>
MySQL表的操作
查看>>
pt-table-checksum解读【转】
查看>>
matlab中类的定义和使用
查看>>
NIO(2):Channel
查看>>
Consistent Hashing算法
查看>>
C++基础--完善Socket C/S ,实现客户端,服务器端断开重连
查看>>
lvs,nginx反向代理,虚拟主机
查看>>
jquip,更简洁的代码
查看>>
【OJ】PAT-A解题报告
查看>>
文档语法
查看>>
利用套接字实现进程通信一例
查看>>
linux中shell变量$#,$@,$0,$1,$2的含义解释
查看>>
常用的shell命令整理
查看>>
A Brief Introduction to the Design of UBIFS
查看>>
了解你的Linux系统:必须掌握的20个命令
查看>>
js setInterval 启用&停止
查看>>
knockoutJS学习笔记04:监控属性
查看>>