Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Sprit Sheets Vs array of PNG files for animations

rameshmrthyrameshmrthy Posts: 18Registered Users
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];
}
}

Replies

  • Duncan CDuncan C Posts: 8,038Tutorial Authors, Registered Users
    I don't know of any support for sprite sheets in UIKit.

    Where I've seen sprite sheets is in OpenGL, and in particular cocos2d.

    OpenGL has a requirement that textures have pixel counts that are a power of 2 in both dimensions for some features to work. (specifically MIP mapping. OpenGL textures are much faster to render when they are a power of 2 even if you don't use MIP mapping.) However, if you have an image that is 1025x1025 pixels, you have to save it at 2048x2048 pixels in order to satisfy the power-of-two-size requirement. That wastes a heck of a lot of space. With sprite sheets, you can cut up that 2048x2048 texture size and put lots of small images in the "dead spaces", thus making maximum use of your memory.

    Beware that UIView animation uses gobs of memory. You only want to use it for pretty small images. If you find yourself trying to create full-screen or nearly full-screen animations, you should look into using a video format like Quicktime instead, since those use compression and streaming and make MUCH more efficient use of limited RAM.
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • rameshmrthyrameshmrthy Posts: 18Registered Users
    Thanks Duncan. Information you provided is very helpful. I think I was not clear on the usage of sprite sheets and now it all makes sense. All my images used for UIView animations are very small and are used to animate characters on scenes and none of them are full screen. Thank you much for your time and feedback.
Sign In or Register to comment.