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

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

问题描述

目前我在计时器上有一个PNG动画,每隔0.01秒就会发射一次。但是,性能不是最佳的,动画明显很慢。我有超过2000张图片。有没有更好的方法来实现这一目标?我发布了类似于以下方法的内容。

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


推荐答案

究竟是什么尺寸 (我的意思是KB和精确的像素大小)是你的PNG?

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

我们已经做了很多工作并且可以毫不费力地在垫上玩动画,大约500x500。所以我只是想知道,谢谢。

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.

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

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

这绝对不可能。没有任何东西以100 fps运行。 20fps是非常平滑,30fps是令人难以置信的平滑,40fps是令人难以置信的人类视觉 - 研究水平如果能够实现平滑并且无法达到100 fps。

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.

这绝对与OpenGLES没什么关系。

This has absolutely utterly nothing whatsoever to do with OpenGLES.

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

The ordinary environment will load frames very quickly for you.

首先回到30 fps (最多!)并丢弃每个第2和第3张图片,以便动画看起来一样。即,i = i ++在您的代码行中变为i + = 3。

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

对你的情况不利?

无论如何,总而言之,你的问题是100 fps。更改为20 fps,您将毫无困难。 并告诉我们精确的图像尺寸(kb / x.y)。

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天全站免登陆