1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > pvr.ccz和png等大图切图工具

pvr.ccz和png等大图切图工具

时间:2023-06-22 04:31:27

相关推荐

pvr.ccz和png等大图切图工具

独角兽企业重金招聘Python工程师标准>>>

此类工具搜索过一些,都不要好用,于是决定自己实现一个。

大图集拆开为小图片,由于是工具,于此效率不太重要,直接用Cocos2dx随手写了一个。

基本思想是直接读取,然后把该SpriteFrame输出为文件即可

#include "HelloWorldScene.h"#include "cocostudio/CocoStudio.h"#include "ui/CocosGUI.h"#include <iostream>#include <iostream>#include <vector>#include <string>#include <stdio.h>#include <fstream>#include <stdlib.h>USING_NS_CC;using namespace std;using namespace cocostudio::timeline;Scene* HelloWorld::createScene(){// 'scene' is an autorelease objectauto scene = Scene::create();// 'layer' is an autorelease objectauto layer = HelloWorld::create();// add layer as a child to scenescene->addChild(layer);// return the scenereturn scene;}// on "init" you need to initialize your instancebool HelloWorld::init(){// 1. super init firstif (!Layer::init()){return false;}vector<string> files;const char *TEM_WORK_FILE_NAME = "filelist.txt";string path = "res";string cmd_txt = "cmd.exe /c DIR " + path + " /S /B > ";cmd_txt += TEM_WORK_FILE_NAME;system(cmd_txt.c_str());fstream f;f.open(TEM_WORK_FILE_NAME, ios::in);vector<string> _queue;string buf;while (getline(f, buf)){//cout << buf << " ... " << endl;//cout<<buffer;if (buf.find(".plist") == string::npos){continue;}string file_ = buf;string file_path = file_.substr(strlen("Resources\\res") + file_.find("Resources\\res") + 1, file_.size() - strlen("Resources\\res") - file_.find("Resources/res"));while (file_path.find("\\") != string::npos){//file_path.replace('\\', '/');file_path[file_path.find("\\")] = '/';}log(file_path.c_str());files.push_back(file_path);}//this->WriteToFile();f.close();//FileUtils::getInstance()->removeFile(TEM_WORK_FILE_NAME);//system("pause");//return 0;//开始转换//vector<string> files;////files.push_back("game_1_1.plist");//files.push_back("game_1_2.plist");//files.push_back("game_1_3.plist");/*files.clear();files.push_back("ui/awake.plist");files.push_back("ui/yingxiongfuben_1.plist");files.push_back("ui/yuanbaobiaoche.plist");files.push_back("ui/xingkong2.plist");files.push_back("ui/synthesis_equipment_4.plist");files.push_back("ui/updateRecommend3.plist");files.push_back("ui/shenmishangcheng.plist");*/for (auto & name : files){string dir = name.substr(0, name.size() - strlen(".plist"));//log((FileUtils::getInstance()->getWritablePath() + "/" + dir).c_str());FileUtils::getInstance()->removeDirectory(FileUtils::getInstance()->getWritablePath() + "/" + dir);FileUtils::getInstance()->createDirectory(FileUtils::getInstance()->getWritablePath() + "/" + dir);SpriteFrameCache::getInstance()->addSpriteFramesWithFile(name);auto mapp = SpriteFrameCache::getInstance()->_spriteFrames;for (auto & cp : mapp){auto sp = Sprite::createWithSpriteFrameName(cp.first.c_str());// Sprite::createWithSpriteFrameName("accomplishTitle.png");sp->setPosition(sp->getTextureRect().size.width / 2, sp->getTextureRect().size.height / 2 );this->addChild(sp);if (sp->getTextureRect().size.width <= 0 || sp->getTextureRect().size.height <= 0){//invalid spritecontinue;;}log(("out:" + dir + "/" + cp.first).c_str());auto re = RenderTexture::create(sp->getTextureRect().size.width, sp->getTextureRect().size.height);re->begin();sp->visit(Director::getInstance()->getRenderer(), Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE), 0);re->end();string path = dir + "/" + cp.first;re->saveToFile(path);}SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(name);TextureCache::getInstance()->removeAllTextures();SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();}//Director::getInstance()->end();return true;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。