It looks like you're new here. If you want to get involved, click one of these buttons!
- (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
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.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome