I do lot of animations in my iOS app using UIImageView.animationImages by passing an array of UIImage objects to the method listed below for animation. Current my array of UIImage objects contains separate PNG files. I know I can do similar animations by using & passing a Sprite Sheet instead of passing an array of separate PNG files. What are the advantages of one over another or Sprite Sheets are meant for a different purpose?
- (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];
}
}