2013-08-19 1 views
2

iOS 게임 (ploy 파일 & plist 파일)에서 일부 이미지 리소스를 얻었습니다. 리소스는 텍스처 패커에 의해 포장됩니다. .png & .plist 파일을 png 이미지로 복원하고 싶지만 어떻게 해야할지 모르겠습니다. The resources I got텍스처 패커로 압축 된 스프라이트 프레임을 복원하는 방법

+0

게시 된 앱에서 가져 왔습니까? 이 경우 해당 자산은 저작권으로 보호된다는 점에 유의하십시오. 기껏해야 내부 작업의 자리 표시 자로 사용할 수 있습니다. 다른 곳에서 가져온 경우 가장 쉽고 가장 좋은 방법은 작성자가 원본 파일을 가져 오는 것입니다. – LearnCocos2D

답변

1

조금 전에 쓴 cocos2d 프로젝트는 이전에 그 목표를 달성했습니다. 기본적으로 CCSpriteFrameCache을 사용하여 plist 정보를로드 한 다음 각 spriteFrame을 반복하여 CCRenderTexture과 함께 아틀라스의 원하는 부분을 '잘라 내기'합니다. 주요 논리는 그냥

https://github.com/zuinqstudio/atlasSplitter

는 희망이 도움이 github.-하는 전체 프로젝트를 업로드 한, 다른 사람이 유용하다고 그냥 경우 이걸

-(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]; 
} 

것 같습니다.

+0

이것은 1 : 1 픽셀 및 색상 정확 추출이 아닐 것입니다. 색상이 약간 변경된 경우 오류가 발생할 수 있습니다. 그렇지 않은 경우 (이 코드 예제에서는 보이지 않습니다) 텍스처 필터링을 끄면 텍스처가 필터링 된 이미지 (예 : 평활화 필터가 적용된 이미지)가됩니다. . 그리고 렌더링 텍스쳐는 1 픽셀 떨어져있는 이상한 버그가 있습니다. 언제 발생했는지, 그것이 고쳐 졌는지는 확실하지 않습니다. – LearnCocos2D