Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

iphone - frame by frame animation

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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...