我从iOS游戏(png文件和plist文件)中获得了一些图像资源。资源由纹理打包器打包。我想恢复.png& .plist文件回到png图片,但我不知道怎么做。
答案 0 :(得分:1)
为了实现这一目标,我写了一个小cocos2d
项目。您基本上使用CCSpriteFrameCache
加载plist信息,然后迭代每个spriteFrame
以使用CCRenderTexture
“切割”所需的地图集。主要逻辑看起来像这样.-
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:PLIST_FILE];
NSDictionary *frames = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrames];
for(id key in frames) {
//NSLog(@"key=%@ value=%@", key, [frames objectForKey:key]);
[self saveSpriteToFile:key inFolder:FOLDER_PATH];
}
}
return self;
}
-(void) saveSpriteToFile:(NSString *)name inFolder:(NSString *) folder {
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:name];
CGSize spriteSize = [sprite contentSize];
float scale = 1;
int nWidth = spriteSize.width;
int nHeight = spriteSize.height;
nWidth *= scale;
nHeight *= scale;
[sprite setPosition:ccp(spriteSize.width / 2, spriteSize.height / 2)];
[sprite setScale:scale];
[self addChild:sprite];
CCRenderTexture* render = [CCRenderTexture renderTextureWithWidth:sprite.contentSize.width height:sprite.contentSize.height];
[render begin];
[sprite visit];
[render end];
//NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//NSString *documentsDirectory = [paths objectAtIndex:0];
[render saveToFile:[NSString stringWithFormat:@"%@/%@", folder, name] format:kCCImageFormatPNG];
[self removeChild:sprite cleanup:YES];
}
为了防止其他人发现它有用,我刚刚将整个项目上传到github .-
https://github.com/zuinqstudio/atlasSplitter
希望它有所帮助。