开发者

Core Animation scaling bizarrely slow?

As part of an iPhone game, I've got buttons that grow a little when you press them, and shrink back when you release (as a way of responding to user input). The code responsible looks like this:

-(void) magnifyButton: (CALayer *) button
{
 button.transform = CATransform3DScale(button.transform, buttonPressScale, buttonPressScale, 1.0);
}

-(void) reduceButton: (CALayer *) button
{
 button.transform = CATransform3DScale(button.trans开发者_运维技巧form, 1.0 / buttonPressScale, 1.0 / buttonPressScale, 1.0);
}

This works great. But if I press a button (each of which is a small image on a CALayer) repeatedly, the animations going on in the background (in an OpenGL view) slow to 10 FPS. This seems absurd to me. I've found a similar problem here, but since I'm using implicit animations I'm not sure how I would go about optimizing in this case.

If anybody can offer a suggestion on how to make this run at a more reasonable speed, I'd be much obliged. Thanks in advance for you


Before an animation begins, to save from having to render the CALayer for each frame, replace it with an image of itself:

button.shouldRasterize = YES;

When the animation is finished, set the property back to NO.


Mixing UIKit and OpenGL is possible but will hurt performance. Things to avoid when combining the two are transparency and transformations. There's probably not a simple way to optimize this, best is ofcourse to do the buttons in OpenGL too.

Gamesfromwithin.com has a few good articles on combining UIKit and OpenGL. This article contains a section on performance (no solution though): http://gamesfromwithin.com/using-multiple-opengl-views-and-uikit

Also check out his presentation on combining the two: http://gamesfromwithin.com/wp-content/uploads/2010/03/GDC10_uikit_opengl.pdf

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜