结合的UIView动画块和OpenGL ES渲染 [英] Combining UIView animation blocks and OpenGL ES rendering

查看:153
本文介绍了结合的UIView动画块和OpenGL ES渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个IP *游戏,我利用双方的UIKit和OpenGL ES 2.0。该UIKit的元素呈现在OpenGL视图,并占据的屏幕空间显著(任意)量。我必须承认,苹果已经做了出色的工作和游戏的帧速率始终是60帧。

I am developing an iP* game and I make use of both UIKit and OpenGL ES 2.0. The UIKit elements are rendered over the OpenGL view and occupy a significant (arbitrary) amount of screen space. I must admit that Apple has done an excellent work and the frame rate of the game is always 60 FPS.

为了得出这个结论,我做了关于性能的多项测试:

In order to come to this conclusion I made many tests regarding the performance:


  1. 我增加了很多静态的(不动),通过对OpenGL视图UIViews的 - !OK

  2. 我的动画使用自定义code相同UIViews(在我的游戏的并条机的方法修改了中心属性) - !好吧

  3. 我增加了UIViews在很多OpenGL ES的元素 - OK!

  4. 我加入了很多移动UIViews下的OpenGL ES的元素 - OK!

所以,现在我想利用Core Animation的框架,以动画的UIKit元素。我利用

So, now I want to make use of the Core Animation Framework in order to animate the UIKit elements. I make use of

[UIView animateWithDuration:delay:options:animations:completion:]

在奥得河进行动画(我指定的iOS 4或更新版本)。

in oder to perform the animations (I target iOS 4 or newer).

现在的问题是,帧速率有这样的怪异行为:有时我得到60 fps的许多许多 UIKit的动画元素(30个元素是OK的我),另外一些时候的帧速率明显低于60 FPS即使有动画UIKit的元素,但我不能用仪器测量它​​!让我来解释更多:当我打开仪器与监测的核心动画和/或OpenGL驱动程序我总是得到60帧。 但是很明显,这是不是这样的,我可以用我的眼睛看到的OpenGL动画,移动比顶部的相应的UIKit动画慢得多。如果我从视图中删除的UIKit元素帧速率来恢复正常。有一个类似的情况我在这里描述发生在任何OpenGL ES的游戏,当用户在玩游戏改变设备的音量。当这显示当前的音量透明视图开始淡出,直至完全消失帧速率急剧下降,但在乐器(我已经做这个测试过),它是贴在60的FPS!

The problem now is that the frame rate has this weird behavior: Sometimes I get 60 fps with many many UIKit animating elements (30 elements is OK for me) and some other times the frame rate is obviously under 60 fps even with a single animating UIKit element but I cannot measure it with Instruments! Let me explain more: When I open Instruments and monitor the core animation and/or OpenGL driver I get always 60 fps. But it is obvious that this is not the case, I can see with my eyes the OpenGL animations to move much slower than the corresponding UIKit animations on the top. If I remove the UIKit elements from the view the frame rate comes back to normal. A similar situation with the one I describe here happens in any OpenGL ES game when the user changes the volume of the device while playing the game. When the transparent view that shows the current volume starts fading out and until it completely fades away the frame rate drops drastically, but in the instruments (I ve made this test too) it is stuck on 60 fps!

所以,总结一下:有时我得到真正的每秒60帧与没有跌宕起伏的运行和其他一些时候,我得到的假块动画60 fps的没有起伏

So, to sum up: sometimes I get real 60 fps with block animations with no ups and downs for a run and some other times I get fake 60 fps with no ups and downs.

你有什么解决办法吗?
所有的测试都与iOS 5.1在iPad 2和iPhone 3GS执行

Do you have any solution to this? All tests were performed on an iPad 2 and iPhone 3GS with iOS 5.1

推荐答案

我设法解决这个问题,现在我可以在我的OpenGL游戏结合了基于块的UIView /核心动画没有任何性能下降。

I managed to solve the problem and now I can combine UIView block/core based animations in my OpenGL game without any performance drop.

解决的办法很简单:


  1. 对于在你的OpenGL应用程序所需的每个UIView的,保持它的界限,中心和你的OpenGL屏幕坐标系转换属性(如创建以下属性:GLBounds,GLCenter,GLTranform),并相应地更新他们时,你改变之一相应的UIView属性。

  2. 当你开始游戏,加载UIViews,但将它们设置为隐藏即可。因此,UIKit中的不画在OpenGL视图,(这样的丢帧问题是完全elliminated)的顶部。相反使用在步骤1中创建的GL *属性,并使用自己绘制的UIViews相应的纹理(您用于每个UIView的图像/色)。

  3. 使用取决于你想要达到的动画块/核心动画动画在隐藏 UIViews属性(边界,中心和转换)(这反过来又更新您的GL *属性),并在你的OpenGL平局方法使用GL *属性来绘制UIViews!要获取范围,中心的实际值,当一个UIView是动画变换(并更新GL *属性)使用其presentationLayer属性。

  1. For each UIView that you want in your OpenGL app, keep its bounds, center and transform properties in your OpenGL screen coordinate system (e.g. create the following properties: GLBounds, GLCenter, GLTranform) and update them accordingly whenever you change one of the corresponding UIView properties.
  2. When you start the game, load the UIViews but set them to hidden. So, UIKit does not draw on top of the OpenGL view (this way the frame drop issue is completely elliminated).Instead draw the UIViews yourself using the GL* properties you created in step 1, and using the corresponding textures (the images/colors you used for every UIView).
  3. Animate the hidden UIViews properties (bounds, center and transform) using block/core animation depending on the animation you want to achieve (which in turn updates your GL* properties) and in your OpenGL draw method use the GL* properties to draw the UIViews! To get the actual values for bounds, center and transform when a UIView is animating (and update the GL* properties) use its presentationLayer property.

最好的,

这篇关于结合的UIView动画块和OpenGL ES渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆