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.
James
source share