0

I want to animate series of images in my app.

I found following code for animate :

 imgView.animationImages = [NSArray arrayWithObjects:  
                           [UIImage imageNamed:@"4.png"],
                           [UIImage imageNamed:@"4.png"],
                           [UIImage imageNamed:@"4.png"],
                           [UIImage imageNamed:@"3.png"],
                           [UIImage imageNamed:@"3.png"],
                           [UIImage imageNamed:@"3.png"],
                           [UIImage imageNamed:@"2.png"],
                           [UIImage imageNamed:@"2.png"],
                           [UIImage imageNamed:@"1.png"],
                           [UIImage imageNamed:@"1.png"],

                           nil];
imgView.animationDuration = 3.00;
imgView.animationRepeatCount = 1.0; 
[imgView startAnimating];

But above code is good when we have less number of images to animate. Else it will decrease the app performance.

Whereas I have to animate too many images.

So which are the other option? And Which is the best way to do this ?

Devang
  • 11,258
  • 13
  • 62
  • 100
  • If this question is for cocos2d-iphone, why aren't you using cocos2d-iphone's animation features? In particular cocos2d caches each texture so that it will be loaded only once, I'm not sure about that if you use UIImage. For best performance regarding animations you'll certainly want to look into animating frames with cocos2d rather than image views. – CodeSmile Dec 13 '11 at 13:53
  • possible duplicate of [Method for animating images (like a movie) on iPhone without using MPMoviePlayer](http://stackoverflow.com/questions/442076/method-for-animating-images-like-a-movie-on-iphone-without-using-mpmovieplayer) – Brad Larson Dec 13 '11 at 19:11

2 Answers2

0
-(void)animationImageChange:(NSString *)imageName{

NSString* imagePath=[[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
[backgroundImage setImage:[UIImage imageWithContentsOfFile:imagePath]];

}

- (void)viewDidLoad {
    [super viewDidLoad];

     doorNumberImage=0;
 timer=[NSTimer scheduledTimerWithTimeInterval:0.1f
                                         target:self
                                       selector:@selector(startAnimation)
                                       userInfo:nil
                                        repeats:YES];

}

-(void)startAnimation{
   [self doorAnimationImageChange:[NSString stringWithFormat:@"%d",doorNumberImage]];
    doorNumberImage=doorNumberImage+1;
}
visakh7
  • 26,380
  • 8
  • 55
  • 69
Dipak Chaudhari
  • 655
  • 4
  • 8
-2

Simplest way is to subclass NSMutableArray, it reports total frames and load/release images on demand.

pinxue
  • 1,736
  • 12
  • 17
  • any sample or more details ? You are telling me same method but replacing it with NSMutableArray ?? – Devang Dec 13 '11 at 05:04
  • I mean you write a subclass of NSMutableArray, override count to report frames, and getObjectAt to load on demand. I don't have sample by hand. – pinxue Dec 13 '11 at 05:18