Combining UIView animation blocks and OpenGL ES rendering

前端 未结 1 1727
悲&欢浪女
悲&欢浪女 2021-02-15 13:20

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 s

1条回答
  •  不知归路
    2021-02-15 14:12

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

    The solution is quite simple:

    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.

    Best,

    0 讨论(0)
提交回复
热议问题