开发者

How do I play a specific range of a UIImageView animation sequence array?

I have a question regarding a png, animated image sequence.

I am loading images from 1 - 35 into a layer and I am initializing the layer with the 1st image using - initWithImage. I have several buttons that want to be able to play different ranges of the image sequence arr开发者_JS百科ay.

Is there a way to play only the images from 1 - 10?

Is there a way to control the range of images played... 11 - 35 or 4 - 20 or whatever?

Of course I tried creating separate layers with separate array's of images and having the layers on top of each other. The problem their is the initWithImage. If I play the second layer I can see the initialized image underneath.

Here is my image sequence code:

- (void) loadAnim05 {
    cAnim = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cof_01.png"]];
    cAnim.center = CGPointMake(78,211);
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 1; i <= 35; i++) 
        [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"cof_%02d.png",i]]];
    cAnim.animationImages = array;
    cAnim.animationDuration = 1.0;
    cAnim.animationRepeatCount = 1;
    [self.view addSubview:cAnim];
    [cAnim release];
}

Thank you very much for any help.


Why don't you maintain an array of images elsewhere and use -subarrayWithRange: method of the NSArray object to pick the images that you want to animate and assign it to the animationImages property of your imageView.

But I don't think UIImageView provides you with mechanism to play a subarray of animationImages.


I am in the process of writing a little animation framework to do exactly this. You can find the code at http://github.com/st3fan/iphone-animation

Key features are:

  • Optimized for PNG images with not too many shapes on a plain background
  • Includes a tool to convert a PNG sequence (like exported from Flash) to a simple one-file container format
  • Keeps frames compressed in memory. Decompresses realtime.
  • Frames are compressed with a simple run-length encoding
  • Typical full screen animation takes ~ 10% CPU

I wrote this specifically for games in the http://tickletapapps.com collection. It works very well for the kind of animations used in those games. Contact me via Github if you need help. The code is work in progress but working pretty well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜