What is the easiest frame-by-frame animation technology in iPhone sdk?

I have been developing the iphone platform for about 3 weeks now, and I am trying to set up frame-by-frame animation with 16 1000x1000 PNG images (with transparency) and schedule the animation about 100 later, so first I tried to use imageNamed to animate all images like this

-(IBAction)startClick1:(id)sender { cloud.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed: @"g0000.png"], [UIImage imageNamed: @"g0001.png"], [UIImage imageNamed: @"g0002.png"], [UIImage imageNamed: @"g0003.png"], [UIImage imageNamed: @"g0004.png"],

Now it worked perfectly in the simulator, but when it came to the device, the device simply rebooted when it first tries to animate, perhaps from known memory problems using imageNamed, so after doing some research, it turned out that imageWithContentsOfFile is supposed to not cache images and I hope it doesnโ€™t force iphone to reboot when requesting animation, so I changed my code to something like this:

- (IBAction)startClick:(id)sender { gordon.animationImages = [NSArray arrayWithObjects: [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"g0001.png" ofType:nil] ], [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"g0002.png" ofType:nil] ], [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"ge0003.png" ofType:nil] ], [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"g0004.png" ofType:nil] ], [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"g0005.png" ofType:nil] ], [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"g0006.png" ofType:nil] ],

Now this works with an error in the simulator and does not work on the device in the same way as the imageNamed method did. So, what is the best and easiest way to animate sequences of images that will work fine on a device? Oh, and when I answer, I remember that I am new to this platform.

+4
source share
4 answers

One significant difference between imageNamed and imageWithContentsOfFile: is that imageNamed returns the image that was previously unpacked.

You can create your own โ€œoptimizedโ€ version without requiring the images to be cached by looking at this answer .

Now I notice that you are uploading 1000x1000 images, but the screen size is only 320x480. Do you zoom out, crop or what? If you're zooming out, consider pre-scaling the image. Also, should your animation be 30 frames per second, or is it more like slideshow animation?

Finally, I would recommend loading animation frames on demand. As you can see, 1000x1000 images take up too much memory to optimize loading. If you save only one in memory at a time, you will not crash, but then you need to be very careful in any pauses in your code. If you use a ken burns effect for a slide show, you can pre-optimize (decompress) one image for drawing over the duration of the slide.

If you are going at 30 frames per second, you need to reduce the image size to speed up the speed.

+3
source

Apple recommends always using the program to resize images instead of the device. This requires sufficient processing power. This can be a serious slowdown by resizing 24 images per second.

+1
source

I'm having trouble getting 3 400x400 transparent layers. On iphone there is no way to get 16 images of this size to work, so re-execution should be the first, second, because for animation I use a repeating timer that invokes rendering every 24 seconds and sets the render to the surface .

0
source

I used this code that works well - www.mode (no space here) jong.com/iPhone/- Search for "PNG Animation" (SO will not let me add the exact link)

It downloads PNG files as needed, not in advance.

This solves the memory problem (you can even use 1000x1000 frames). However, you are still faced with a disk space problem. The program will be great for large / many animations.

NTN

Oded.

0
source

Source: https://habr.com/ru/post/895952/


All Articles