更快的iPhone PNGanimation

目前我有一个定时器的PNGanimation,每0.01秒发射一次。 但是,performance并不理想,animation显然很慢。 我有超过2000张图片。 有没有更好的方法来完成这个? 我已经发布了类似于以下方法的内容。

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++; } 

究竟什么大小 (我的意思是KB,也是确切的像素大小)是你的PNG?

我们在这方面做了很多工作,并且在播放animation的时候没有任何问题,比如500×500。 所以我只是想知道,谢谢。

一个直接的问题是你试图以100Hz的速度运行,每秒100次!

这是绝对不可能的。 没有任何运行在100 fps。 20fps是“非常平滑”,30fps是“惊人的平滑”,40fps是“如果可以实现的,令人难以置信的人类视觉研究水平”,100fps是无法实现的。

这与OpenGLES完全没有任何关系。

普通的环境会很快为你加载帧。

所以先回到30帧/秒 (最多!),扔掉每一个第二和第三个图像,所以animation看起来是一样的。 即“i = i ++”在你的代码行中变成“i + = 3”。

这可能是这个压倒性的问题,正在破坏你的努力!

下一个问题! 如果你像这样加载每个图像,几乎可以肯定需要随时随地释放它们

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

如果你不这样做,它不会工作。

下一个问题! 使用video的想法是不好的,但你可以使用每天的animation图像? 从而…

 #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]; 

对你的情况没有好处?

无论如何,一句话你的问题是100帧/秒。 改为20帧/秒,你就没有麻烦了。 让我们知道精确的图像大小(kb / xy)。

用于pipe理fps的CADisplayLink如何?

OpenGLES需要花时间将图像转换为纹理,纹理需要仔细的内存pipe理。 当内存不够时,会产生一个完整的白色纹理。

将您的animation编码为video,然后播放video。