My app uses Cocos2D for animation and 2D rendering, but the "game lobby" (that's not what it is, but for all intents and purposes) is all standard UIView
/UIKit
code.
I have a UIViewController
subclass that has its main view set in the XIB file as an EAGLView
. When I put all the Cocos loading code into viewDidLoad
, everything works as expected, except that there is a 1-2 second freeze while Cocos loads all my textures.
I have about 20 textures that I preload into the CCSpriteFrameCache
before running my scene - so my animations are smooth immediately.
I tried to move this texture loading code to my view controller's init
method -- but when I try this, Cocos crashes, seemingly because there is no OpenGL context to work with.
What I want to do is, while displaying a UIViewController
's main view (and not blocking the main thread), I'd like to load textures in the background, and then when finished, transition between that UIView
and the OpenGL EAGLView
.
I am aware that there is an addImageAsync:
call in Cocos now, so it's really just a matter o开发者_如何转开发f somehow "passing around an offscreen EAGLView/EAGLContext" that I can eventually stick into Cocos when I am ready to display that view.
Does anyone have any pointers on an elegant solution to this?
The solution to this problem was to create a separate EAGLContext, using which I would load the textures. That EAGLContext needed to share a EAGLSharegroup with the actual GL view that I used to render the content. So the steps worked like this:
- Create/load/show my UI View
- Create my to-be-used EAGLView
- Snag the EAGLSharegroup off that EAGLView
- Create a EAGLContext using that sharegroup
- Load my textures using that EAGLContext
- Switch my UIView to the EAGLView
- Textures are loaded and available
精彩评论