views:

1316

answers:

4

Hello, I have been trying to set up an animation in xcode for a long time now, At first I started trying to animate 100 1000x1000 pngs, but those images were too big for the iphone, now I am trying to animate 100 320x480 pngs and it seems to animate fine up until about 40 frames in, then the app crashes, so, is there any other method of animation that wouldn't do this? It's probably just because this code loads too much images for the iphone to handle, is there some other method i can use to get the app to stop crashing? Or can I optimize this code further? (By the way i'm new to the iphone platform so keep in mind when answering)

- (IBAction)startClick1:(id)sender{

spud123.animationImages = [NSArray arrayWithObjects:
        [UIImage imageNamed: @"spud1230000.png"],
        [UIImage imageNamed: @"spud1230001.png"],
        [UIImage imageNamed: @"spud1230002.png"],
        [UIImage imageNamed: @"spud1230003.png"],
        [UIImage imageNamed: @"spud1230004.png"],
        [UIImage imageNamed: @"spud1230005.png"],
        [UIImage imageNamed: @"spud1230006.png"],
        [UIImage imageNamed: @"spud1230007.png"],
        [UIImage imageNamed: @"spud1230008.png"],
        [UIImage imageNamed: @"spud1230009.png"],
        [UIImage imageNamed: @"spud1230010.png"],
        [UIImage imageNamed: @"spud1230011.png"],
        [UIImage imageNamed: @"spud1230012.png"],
        [UIImage imageNamed: @"spud1230013.png"],
        [UIImage imageNamed: @"spud1230014.png"],
        [UIImage imageNamed: @"spud1230015.png"],
        [UIImage imageNamed: @"spud1230016.png"],
        [UIImage imageNamed: @"spud1230017.png"],
        [UIImage imageNamed: @"spud1230018.png"],
        [UIImage imageNamed: @"spud1230019.png"],
        [UIImage imageNamed: @"spud1230020.png"],
        [UIImage imageNamed: @"spud1230021.png"],
        [UIImage imageNamed: @"spud1230022.png"],
        [UIImage imageNamed: @"spud1230023.png"],
        [UIImage imageNamed: @"spud1230024.png"],
        [UIImage imageNamed: @"spud1230025.png"],
        [UIImage imageNamed: @"spud1230026.png"],
        [UIImage imageNamed: @"spud1230027.png"],
        [UIImage imageNamed: @"spud1230028.png"],
        [UIImage imageNamed: @"spud1230029.png"],
        [UIImage imageNamed: @"spud1230030.png"],
        [UIImage imageNamed: @"spud1230031.png"],
        [UIImage imageNamed: @"spud1230032.png"],
        [UIImage imageNamed: @"spud1230033.png"],
        [UIImage imageNamed: @"spud1230034.png"],
        [UIImage imageNamed: @"spud1230035.png"],
        //and so on to 100
        nil];

[spud123 setAnimationRepeatCount:1];
spud123.animationDuration =5.7;
[spud123 startAnimating];

}

Ps: Iv'e tried NSTimer, but I can't get that to stop repeating the animation

+4  A: 

This is not an animation problem it's a design problem.

First off, just take a step cack and calculate your application's memory requirements: When decompressed, each of those PNGs uses 614400 bytes. So a hundred of them use 61440000 bytes: over 60 megabytes. That's a little much to expect from a phone.

If you really need to display a different image for every frame, you should be using video. Video has a lot of technology to compress images and reduce the processing and memory requirements when displaying a lot of large images sequentially.

If you need this to be an animation with more control, I suggest you need to analyse what is moving and only animate that - draw a single background and then animate smaller images over that.

Finally, if this approach doesn't work, you are going to have to learn OpenGL to achieve the performance you need.

Without knowing more about your app, it is difficult to advise.

Roger Nolan
Well, I wouldn't mind using video, but it would need to be transparent video, do you know of any useful tutorials on video implementation? And how difficult would you say it was to learn openGL? Are there any animation tutorials on openGL? And you say that i'm asking too much from a phone, well I have seen other developers implement much more complicated animations into their apps. Thanks for your advice anyway.
Amanda
You might have seen people do things that look like the effect you want from an app, what you haven't seen is someone display 100 full screen images as a UIImage animation.
Roger Nolan
Hey Roger Nolan,im having a similar issue, however my pngs are 320 x 480 and are about 75 or so frames. i tried compressing to pvr, but it was very lossy. not ever worth using.my current size of the pngs once brought into openGL is about 78 mbs total. but wondering what size i would need to bring this down.all the best,keuminotti
keuminotti
You can often get 10Mb on a phone but you cannot rely on it. You need a different approach or to go and think of a different application.
Roger Nolan
thanks ryan. i have changed my strategy as I have found out that the size of each png in your animation is irrelevant, but rather, the amount of frames you are using in an openGL animation. Do you know roughly how many frames you can animate until the processer reacting poorly? i have about 75 or so frames.all the best,keuminotti
keuminotti
A: 

Often the frames in an animation are very similar. So one potential solution is to load a few images... then animate them using OpenGL. This works well for, say, a ball bouncing. Not sure what images you're animating.

MrDatabase
well not to jump in, im animating a batton that is being thrown in the air, the baton has different angles and is about 75 frames of pngs. but there are two sets, one of the background that its on, and then a series of trans. pngs of the batton. im wondering at what point or how many frames will make the processor react poorly.
keuminotti
sounds like that can be done fairly easily with OpenGL. The general approach is every time you call render scene draw the background then draw the baton at a specific angle and height (both of which changed over time)
MrDatabase
+1  A: 

You need to consider your application memory use carefully, but just so you know the options, I've successfully used a modified class based on http://www.modejong.com/iPhone/PNGAnimatorDemo.zip which can, on the first generation iPad hardware, handle 15fps full screen (1024x768) png animations. But keep an eye on your application bundle size. This is definitely not going to be the best option for most applications.

Michael Baltaks
A: 

you will use stopAnimating

heyram