IPhone SDK: lengthy animation with "animationImages" problem

I am trying to tweak the animation in xcode for a long time, At first I started trying to animate 100 1000x1000 png, but these images were too big for iphone, now I am trying to animate 100 320x480 pngs and it seems like it animates to 40 frames per second, then the application crashes, so is there any other way of animation that wouldn't do this? Probably just because this code uploads too many iphone images for processing, is there any other method I can use to get the application to crash? Or can I optimize this code further? (By the way, I'm new to the iphone platform, so keep in mind when replying)

- (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 not stop this by repeating the animation

0
source share
3 answers

This is not an animation problem, this is a design problem.

First of all, just take a step and calculate the memory requirements of the application: When unpacking, each of these PNGs uses 614,400 bytes. Thus, one hundred of them use 61440000 bytes: more than 60 megabytes. This is a little to be expected from the phone.

If you really need to display a different image for each frame, you should use a video. Video has many technologies for compressing images and reducing processing and memory requirements when displaying a large number of large images in sequence.

If you want this to be an animation with more control, I suggest you analyze what is moving and only animate - draw a single background and then leave smaller images above it.

Finally, if this approach does not work, you need to learn OpenGL in order to achieve the required performance.

Without knowing more about your application, it’s hard for you to advise.

+4
source

You need to carefully study the memory usage of the application, but so that you know the parameters, I successfully used a modified class based on http://www.modejong.com/iPhone/PNGAnimatorDemo.zip , which can handle PNG animation on the hardware of the first generation iPad full screen (1024x768). But keep an eye on the size of the application package. This will definitely not be the best option for most applications.

+2
source

Often frames in an animation are very similar. So one possible solution is to upload multiple images ... then animate them using OpenGL. This works well, say, under the kick of the ball. Not sure which images you are animating.

0
source

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


All Articles