开发者

Squeezing just a little more performance out of Core Animation

I have a game that's moving fewer than 10 small animated UIImageViews at once, maximum. I'm driving their animation with a CADisplay timer running at 60fps. Here is an example of how I move the views in my update method:

// for each insect in insectArray
insectView.center = insect.hitCenter // I pull a position from my model object

The graphics are 32 x 32 pixels with up to 5 animation frames each, if that helps. They have an alpha channel for transparency. I've profiled and eliminated any in-game calculations as a bottleneck. I've also made the opacity property = YES, for a very small speedup. Having the animated frames playing or not makes no difference.

The frame rates are mostly great, except on older devices like the iPhone 1G and 3G. There I get intermittent stuttering.

Before switching to OpenGL, is there any开发者_运维知识库 way to get a bit more performance?


I experienced the same kind of bottleneck with CoreAnimation; it is very limited in terms of system complexity that you can display with decent performance. From what I have read and discussed with others, there is no silver bullet for you (or me) there, sorry!

My usage was actually quite close to yours (no animated frames, though), and using OpenGL ES made it go from painfully sluggish to perfectly snappy, so there's hope for you!


CoreAnimation isn't designed for frame-by-frame animation, you tell it a few keyframes and times, and it will do the rest for you. Why not switch to OpenGL? You can't support the old devices forever...


I agree with FX that there is no silver bullet, but if you provided a little more code, we could make some specific suggestions. Here are a few general ones:

  • Don't round corners using -setCornerRadius on the UIImageView's layer. You'd never believe how much this can degrade performance

  • If you're using drop shadows behind your view, make sure you specify a shadow path on the layer as well.

  • Try turning -shouldRasterize on on the UIImageView layer: [[insectView layer] setShouldRasterize:YES];

Hate to say it, but after this, as others have said, OpenGL is the only other choice.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜