2012-07-19 1 views
2

iIImageView.animationImages를 사용하여 iOS 앱에서 애니메이션을 만들기 위해 UIImage 객체 배열을 아래에 나열된 메서드에 전달하여 애니메이션을 많이 만듭니다. 현재 내 UIImage 객체 배열에는 별도의 PNG 파일이 들어 있습니다. 나는 별도의 PNG 파일의 배열을 전달하는 대신 Sprite Sheet를 전달하여 &을 사용하여 유사한 애니메이션을 수행 할 수 있음을 알고 있습니다. 다른 스프레드 시트의 장점은 다른 목적을위한 것입니까?Sprit Sheets 애니메이션 용 PNG 파일의 배열

- (void) startImageViewAnimation:(UIImageView *)imageView WithImages:(NSArray*)imageArray orBuildArrayWithImage:(NSString *)imageName duration:(CGFloat)duration repeatCount:(NSInteger)repeatCount soundFile:(NSString *)soundFile stopSoundAfterDuration:(CGFloat) stopSoundDuration 
{ 

    if([imageName length] != 0) 
    { 
     NSMutableArray *array = [[NSMutableArray alloc] init]; 
     UIImage *image; 
     int index = 1; 
     NSString *string; 
     do 
     { 
      string = [NSString stringWithFormat:@"%@%02d.png", imageName, index++]; 
      image = [UIImage imageNamed:string]; 
      if(image) 
       [array addObject:image]; 
     } while (image != nil); 

     imageView.animationImages = array; 
     [array release]; 
    } 
    else 
    { 
     imageView.animationImages = imageArray; 
    } 
    imageView.animationDuration = duration; 
    imageView.animationRepeatCount = repeatCount; 
    [imageView startAnimating]; 

    if([soundFile length] != 0) 
    { 
     [self loadSoundEffectAudio:soundFile]; 
    } 
} 

답변

0

스프라이트 시트 애니메이션의 모든 프레임을 기억하고, DIFF (X)에로드 한 "장"에 들어갈 수있는 매우 작은 애니메이션에만 유용 Y 오프셋은 상이한 프레임 데이터를 액세스하기 위해 사용된다. 애니메이션이 길거나 애니메이션이 더 큰 경우 스프라이트 시트는 전혀 가치가 없습니다. 과거에는 캐릭터 스프라이트가 다소 작아서 많은 시트가 하나의 시트에 들어갈 수 있었고 펀치와 같은 짧은 애니메이션은 한 프레임에서 다음 프레임으로 메모리를 교체해야 할 필요가 없었기 때문에 신속하게 애니메이션을 적용 할 수있었습니다. 작은 크기의 애니메이션을 제외하면 UIImageView.animationImages를 사용해서는 안됩니다. 적당한 크기의 중간 크기의 애니메이션을 사용하더라도 메모리가 부족하고 장치가 손상 될 수 있기 때문입니다. 더 나은 접근법에 대한 자세한 정보는이 질문에 대한 내 답변에서 찾을 수 있습니다 How to do animations using images efficiently in iOS