更快的 iPhone PNG 动画 [英] Faster iPhone PNG Animations

查看:14
本文介绍了更快的 iPhone PNG 动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Currently I have a PNG animation on a timer that is firing every .01 seconds. However, performance isn't optimal and the animation is visibly slow. I have over 2000 images. Is there a better way to accomplish this? I've posted something similar to my approach below.

timer_ = [NSTimer scheduledTimerWithTimeInterval:.01 target:self
selector:@selector(switchImage) userInfo:nil repeats:YES];


-(void)switchImage 
{
   p = [p stringByAppendingFormat:@"/Movie Clipping 1 000%i.png",i];
   imageView_.image = [UIImage imageWithContentsOfFile:p];
   i = i++;
}

解决方案

exactly what size (I mean KB and also the exact pixel size) are your PNGs?

We have done a lot of work on this and have no trouble playing animations, on the pad, of about say 500x500. So I'm just wondering, thanks.

One immediate problem is that you are trying to run at 100hz, 100 times per second??!

That is absolutely impossible. Nothing runs at 100 fps. 20fps is "extremely smooth", 30fps is "staggeringly smooth", 40fps is "mindboggling human-vision-research-level smooth if it could be achieved" and 100 fps cannot be achieved.

This has absolutely utterly nothing whatsoever to do with OpenGLES.

The ordinary environment will load frames very quickly for you.

So first go back to 30 fps (at most!) and throw away every 2nd and 3rd image so the animation looks the same. ie, "i=i++" becomes "i+=3" in your line of code.

it is likely that this is the overwhelming problem that is ruining your efforts!

Next problem! If you do load up each image like that as you go, you will almost certainly need to release them all on the fly as you go with a pair of lines something like...

[happy.image release];
happy.image = [[UIImage alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"blah" ofType:@"png"]];

If you don't do that it just won't work.

Next problem! The idea of using video is no good, but could you just use an everyday animated image? Thus...

#define BI(X) [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@X ofType:@"tif"]]

    happyDays  = [[NSArray alloc] initWithObjects:
            BI("hh00"), BI("hh01"), BI("hh02"), BI("hh03"), BI("hh04"), BI("hh05"), BI("hh06"), BI("hh07"), BI("hh08"), BI("hh09"), 
            BI("hh10"), BI("hh11"), BI("hh12"), BI("hh13"), BI("hh14"), BI("hh15"), BI("hh16"), BI("hh17"), BI("hh18"), BI("hh19"), etc etc etc
            nil];

    animArea.animationImages = happyDays;
    animArea.animationDuration = 2.88;
    // that is overall seconds. hence: frames divided by about 30 or 20.
    [animArea startAnimating];

No good for your situation?

Anyway, in one word your problem is 100 fps. Change to 20 fps and you will have no trouble. And let us know the precise image size (kb / x.y).

这篇关于更快的 iPhone PNG 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆