Faster iPhone PNG Animations(更快的 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 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更快的 iPhone PNG 动画


基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01