0

I have a list of png images that I want them to show one after another to show an animation. In most of my cases I use a UIImageView with animationImages and it works fine. But in a couple of cases my pngs are 1280*768 (full screen iPad) animations with 100+ frames. I see that using the UIImageView is quite slow on the emulator (too long to load for the first time) and I believe that if I put it on the device it will be even slower.

Is there any alternative that can make show an image sequence quite smoothly? Maybe Core Animation? Is there any working example I can see?

weberc2
  • 7,423
  • 4
  • 41
  • 57
Panos
  • 7,227
  • 13
  • 60
  • 95

3 Answers3

4

Core Animation can be used for vector/key-frame based animation - not image sequences. Loading over a hundred full-screen PNGs on an iPad is a really bad idea, you'll almost certainly get a memory warning if not outright termination.

You should be using a video to display these kind of animations. Performance will be considerably better. Is there any reason why you couldn't use a H.264 video for your animation?

lxt
  • 31,146
  • 5
  • 78
  • 83
  • lxt is correct. If you have over 100 frames for a fullscreen animation image sequencing isn't the right method to be going after. You should be looking for video or splitting it up into actual sprites and animating their movement in code. – Ryan Poolos Dec 11 '12 at 15:39
  • I want these animations to have alpha channel for transparency in most of them. Will a video with H.264 allow transparency? – Panos Dec 11 '12 at 15:50
  • No - if you need alpha you're probably going to need to find an alternative method (probably animating individual objects using keyframes or paths). As Minthos suggests, you can try and use OpenGL, but with over a hundred 1024px textures this is probably not a viable solution. – lxt Dec 11 '12 at 16:37
  • @lxt With pvrtc the textures will stay compressed in gpu memory so it is actually viable. They will take 4 bits per pixel, or about 50-100 MB for a whole animation. And the link I posted in my comment suggests it is possible (but not easy) to draw transparent video. – Minthos Dec 11 '12 at 16:44
  • That kind of memory allocation is *really* pushing it on the original iPad. It depends what hardware you want to target. You can certainly chromakey video, but if you're doing complex alpha blending it's going to be sub-optimal. I'm not saying it can't be done, just that the effort may well outweigh the cost. – lxt Dec 11 '12 at 20:50
3

Make a video of your pictures. It is the simplest and probably most reasonable approach.

If you want really good performance and full control over your animation, you can convert the pictures to pvrtc4 format and draw them as billboards (textured sprites) with OpenGL. This can be a lot of work if you don't know how to do it.

Minthos
  • 900
  • 4
  • 13
  • does video support alpha channel for transparency? As it is now, the images have transparency in certain places to allow other components under them to be visible and touchable. Will a video offer this feature? – Panos Dec 11 '12 at 15:56
  • you could try to make sense of this: http://stackoverflow.com/questions/1401517/iphone-sdk-how-to-play-a-video-with-transparency – Minthos Dec 11 '12 at 16:04
0

Look at the second example

http://www.modejong.com/iPhone/

Extracts from http://www.modejong.com/iPhone/

There is also the UIImageView.animationImages API, but it quickly sucks up all the system memory when using more than a couple of decent size images.

I wanted to show a full screen animation that lasts 2 seconds, at 15 FPS that is a total of 30 PNG images of size 480x320. This example implements an animation oriented view controller that simply waits to read the PNG image data for a frame until it is needed.

Instead of alllocating many megabytes, this class run in about a half a meg of memory with about a 5-10% CPU utilization on a 2nd gen iPhone. This example has also been updated to include the ability to optionally play an audio file via AVAudioPlayer as the animation is displayed.

Desmond
  • 5,001
  • 14
  • 56
  • 115