pvr批量转小图png.docx_第1页
pvr批量转小图png.docx_第2页
pvr批量转小图png.docx_第3页
pvr批量转小图png.docx_第4页
pvr批量转小图png.docx_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Plist2Png.h 文件内容#ifndef _PLIST2PNG_SCENE_H_#define _PLIST2PNG_SCENE_H_#include cocos2d.hclass Plist2Png : public cocos2d:Layerpublic: / theres no id in cpp, so we recommend returning the class instance pointer static cocos2d:Scene* createScene(); / Heres a difference. Method init in cocos2d-x returns bool, instead of returning id in cocos2d-iphone virtual bool init(); / implement the static create() method manually CREATE_FUNC(Plist2Png); void getAllFileNameWithPath(std:vector *theResultVec,std:string filePath,int depth=0); void SavePngFromPlist(std:string plistName,std:string imageSaveDir = );void onSaveImageToFile(cocos2d:RenderTexture *render,const std:string& filename, bool isRGBA,cocos2d:CustomCommand *_saveToFileCommand);private:;#endif / _HELLOWORLD_SCENE_H_Plist2Png.cpp 文件内容#include Plist2Png.h#include cocos2d.h#ifdef _WIN32#include #else#include #include #include #include #endifUSING_NS_CC;Scene* Plist2Png:createScene() / scene is an autorelease object auto scene = Scene:create(); / layer is an autorelease object auto layer = Plist2Png:create(); / add layer as a child to scene scene-addChild(layer); / return the scene return scene;/ on init you need to initialize your instancebool Plist2Png:init() / / 1. super init first if ( !Layer:init() ) return false; std:vector allPlistVector; getAllFileNameWithPath(&allPlistVector,FileUtils:getInstance()-fullPathForFilename(monsters); for (int i=0; igetWritablePath()+tempDir; long dirOffset = tempDir.find_last_of(.); tempDir = tempDir.substr(0,dirOffset); tempDir = tempDir+ /; SavePngFromPlist(allPlistVectori, tempDir); return true;void Plist2Png:getAllFileNameWithPath(std:vector *theResultVec,std:string filePath,int depth) DIR *dp; struct dirent *entry; struct stat statebuf; if (dp=opendir(filePath.c_str()=NULL) fprintf(stderr,cannot open directory :%sn,filePath.c_str(); return ; chdir(filePath.c_str(); while (entry=readdir(dp)!=NULL) lstat(entry-d_name, &statebuf); if (S_ISDIR(statebuf.st_mode) if (strcmp(., entry-d_name)=0| strcmp(., entry-d_name)=0) continue; printf(%*s%s/n,depth,entry-d_name); std:string tempDirName = filePath + / + entry-d_name; getAllFileNameWithPath(theResultVec,tempDirName,depth+4); else std:string fileName = entry-d_name; printf(%*s%sn,depth,entry-d_name); if (fileName.find(.plist)!=-1) theResultVec-push_back(filePath+ /+fileName); /存入路径为沙盒路径,请去沙盒路径下找分解的png小图。不懂得请百度 void Plist2Png:SavePngFromPlist(std:string plistName,std:string imageSaveDir) SpriteFrameCache:getInstance()-addSpriteFramesWithFile(plistName);std:string fullPath = FileUtils:getInstance()-fullPathForFilename(plistName);auto dict = FileUtils:getInstance()-getValueMapFromFile(fullPath);std:string texturePath();if (dict.find(metadata) != dict.end()ValueMap& metadataDict = dictmetadata.asValueMap();/ try to read texture file name from meta datatexturePath = metadataDicttextureFileName.asString();if (!texturePath.empty()texturePath = FileUtils:getInstance()-fullPathFromRelativeFile(texturePath.c_str(), plistName);else/ default image nametexturePath = plistName;size_t startPos = texturePath.find_last_of(.); texturePath = texturePath.erase(startPos);texturePath = texturePath.append(.png);CCLOG(cocos2d: SpriteFrameCache: Trying to use file %s as texture, texturePath.c_str();auto *texture = Director:getInstance()-getTextureCache()-addImage(texturePath.c_str();if (!texture)CCLOG(cocos2d: SpriteFrameCache: Couldnt load texture);return;auto & framesDict = dictframes.asValueMap();if(imageSaveDir.empty()imageSaveDir = FileUtils:getInstance()-getWritablePath() + output/;FileUtils:getInstance()-createDirectory(imageSaveDir);log(ImageSaveDir: %s,imageSaveDir.c_str();for (auto iter = framesDict.begin(); iter != framesDict.end(); +iter)auto & frameDict = iter-second.asValueMap();std:string spriteFrameName = iter-first;std:string imageFilePath = imageSaveDir + spriteFrameName;auto *sprite = Sprite:createWithSpriteFrameName(spriteFrameName);if(!sprite)continue;sprite-setAnchorPoint(Vec2(0,0);auto *render = CCRenderTexture:create(sprite-getContentSize().width,sprite-getContentSize().height);render-begin();sprite-visit();render-end();bool isRGBA = false;if (spriteFrameName.find(.png) != std:string:npos)isRGBA = true;else if (spriteFrameName.find(.jpg) != std:string:npos)isRGBA = false;elseCCLOG(Only PNG and JPG format are supported now! %s,spriteFrameName.c_str();continue;auto * saveToFileCommand = new cocos2d:CustomCommand();saveToFileCommand-init(_globalZOrder);saveToFileCommand-func = CC_CALLBACK_0(Plist2Png:onSaveImageToFile, this, render, imageFilePath, isRGBA,saveToFileCommand);Director:getInstance()-getRenderer()-addCommand(saveToFileCommand);void Plist2Png:onSaveImageToFile(Rend

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论