3

i wanna knw an alternate to this animation code..

    -(void)movetree{
    //[tree1 release];
    treeMove = YES;
    tree1.animationImages = [NSArray arrayWithObjects: 
        [UIImage imageNamed:@"moving trees1.png"],
        [UIImage imageNamed:@"moving trees2.png"],
        [UIImage imageNamed:@"moving trees3.png"],
        [UIImage imageNamed:@"moving trees4.png"],
        [UIImage imageNamed:@"moving trees5.png"],
        [UIImage imageNamed:@"moving trees6.png"],
        [UIImage imageNamed:@"moving trees7.png"],
        [UIImage imageNamed:@"moving trees8.png"],
        [UIImage imageNamed:@"moving trees9.png"],
        [UIImage imageNamed:@"moving trees10.png"],
        [UIImage imageNamed:@"moving trees11.png"],
        [UIImage imageNamed:@"moving trees12.png"],
        [UIImage imageNamed:@"moving trees13.png"],
        [UIImage imageNamed:@"moving trees14.png"],
        [UIImage imageNamed:@"moving trees15.png"],
        [UIImage imageNamed:@"moving trees16.png"],
        [UIImage imageNamed:@"moving trees17.png"],
        [UIImage imageNamed:@"moving trees18.png"],
        [UIImage imageNamed:@"moving trees19.png"],
        [UIImage imageNamed:@"moving trees20.png"],
        [UIImage imageNamed:@"moving trees21.png"],
        [UIImage imageNamed:@"moving trees22.png"],
        [UIImage imageNamed:@"moving trees23.png"],
        [UIImage imageNamed:@"moving trees24.png"],
        [UIImage imageNamed:@"moving trees25.png"],
        [UIImage imageNamed:@"moving trees26.png"],
        [UIImage imageNamed:@"moving trees27.png"],
        [UIImage imageNamed:@"moving trees28.png"],
        [UIImage imageNamed:@"moving trees29.png"],
        [UIImage imageNamed:@"moving trees30.png"],
        [UIImage imageNamed:@"moving trees31.png"],
        [UIImage imageNamed:@"moving trees32.png"],
        [UIImage imageNamed:@"moving trees33.png"],
        [UIImage imageNamed:@"moving trees34.png"],
        [UIImage imageNamed:@"moving trees35.png"],
        [UIImage imageNamed:@"moving trees36.png"],
        [UIImage imageNamed:@"moving trees37.png"],
        [UIImage imageNamed:@"moving trees38.png"],
        [UIImage imageNamed:@"moving trees39.png"],
        [UIImage imageNamed:@"moving trees40.png"],
        [UIImage imageNamed:@"moving trees41.png"],
        [UIImage imageNamed:@"moving trees42.png"],
        [UIImage imageNamed:@"moving trees43.png"],
        [UIImage imageNamed:@"moving trees44.png"],
        [UIImage imageNamed:@"moving trees45.png"],
        [UIImage imageNamed:@"moving trees46.png"],
        [UIImage imageNamed:@"moving trees47.png"],
        [UIImage imageNamed:@"moving trees48.png"],
        [UIImage imageNamed:@"moving trees49.png"],
        [UIImage imageNamed:@"moving trees50.png"],
        [UIImage imageNamed:@"moving trees51.png"],
        [UIImage imageNamed:@"moving trees52.png"],
        [UIImage imageNamed:@"moving trees53.png"],
        [UIImage imageNamed:@"moving trees54.png"],
        [UIImage imageNamed:@"moving trees55.png"],
        [UIImage imageNamed:@"moving trees56.png"],
        [UIImage imageNamed:@"moving trees57.png"],
        [UIImage imageNamed:@"moving trees58.png"],
        [UIImage imageNamed:@"moving trees59.png"],
        [UIImage imageNamed:@"moving trees60.png"],nil];

 // all frames will execute in 1.75 seconds
 tree1.animationDuration =1.75;
 // repeat the annimation forever
 tree1.animationRepeatCount = 0;
 // start animating

 [tree1 startAnimating];
 // add the animation view to the main window 
 //[bgview addSubview:campFireView];

 [tree1 release]; 

 player.numberOfLoops = -1;
 [player play];


 }

Is there any other way to show animation using frames?? this method seems to be heavier and it crashes alot..

Shrey
  • 1,959
  • 2
  • 21
  • 44

2 Answers2

4

Try using PNG Animation method by Moses DeJong. From his words:

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.

I believe it basically uses UIImageView to cache up AVAudioPlayer.

cregox
  • 17,674
  • 15
  • 85
  • 116
  • 3
    The PNG Animation example mentioned above will do the basics without crashing due to running out of memory (why your code crashes). A much more complete implementation that is significantly optimized cab be found here: http://www.modejong.com/AVAnimator/ –  May 10 '11 at 21:01
  • Looks like the man himself has spoken... Hey @MoDJ you could have suggest and edit or, even better (for you), added your own answer. ;) - but thanks for commenting! :) – cregox May 10 '11 at 21:51
0

there is a call back for the animation, something like animation finished, [self performSelector:@selector(stopAnimation) withObject:nil afterDelay:3]; cant remember offhand - But the usual way is, once the animation is done this method is called and then u can release. The usual EXC_BAD_ACCESS could be one or more of your images do not exist, double check all the image names and verify if they exist in your resource folder. BUt that's the only as far as i know for animation images. helper link http://iosdevelopertips.com/graphics/animated-gif-animated-images-iphone-style.html

Cœur
  • 37,241
  • 25
  • 195
  • 267
Veeru
  • 4,936
  • 2
  • 43
  • 61
  • what happens is when i call the animation xib first..everything works f9..but if i first call any other xib and then navigate to the animation xib..it crashes.. :( – Shrey Jan 06 '11 at 06:35