Frame animation

I want to change 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 harder and it drops a lot.

+3
source share
2 answers

Try using the Moses Dejon PNG animation method . According to him:

This example implements an animation oriented view controller that just waits to read PNG image data for until it is needed. Instead of alllocating a lot of megabytes, this class run about half a megabyte of memory with about 5-10% CPU usage on a second-generation iPhone.

I find that I mainly use UIImageView to cache AVAudioPlayer.

+4
source

there is a callback for the animation, something like the animation is complete, [self performSelector:@selector(stopAnimation) withObject:nil afterDelay:3]; can not remember carelessly - But the usual way is, after the animation is completed, this method is called, and then you can release it. Normal EXC_BAD_ACCESS may be one or more of your images does not exist, double-check all image names and check if they exist in your resource folder. BUt that I know only for animated images. reference link http://iosdevelopertips.com/graphics/animated-gif-animated-images-iphone-style.html

0
source

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


All Articles