How to load ccbi files using CCBReader in background thread?

I recently used CocosBuilder to create a game interface. I can upload ccbi files to the main stream without any problems. But when I load it into the background thread. I got an empty / node layer with a black background. So my question is how to load them in the background thread correctly?

+4
source share
1 answer

I find a solution. I can upload ccbi files and run the loading animation at the same time. I don’t know if it’s right, but it works for me. Here is the code. The solution is found in the Cocos2d multipoint test case.

//loading animations here [self pushLoadingAnimation]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ CCGLView *view = (CCGLView*)[[CCDirector sharedDirector] view]; NSAssert(view, @"Do not initialize the TextureCache before the Director"); EAGLContext *auxGLcontext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:[[view context] sharegroup]]; if( [EAGLContext setCurrentContext:auxGLcontext] ) { // load the ccbi files here [self readCCBIfile]; //push the scene in main thread dispatch_async(dispatch_get_main_queue(), ^{ [[CCDirector sharedDirector] replaceScene:world]; }); glFlush(); [EAGLContext setCurrentContext:nil]; } else { CCLOG(@"cocos2d: ERROR: TetureCache: Could not set EAGLContext"); } }); 
+3
source

Source: https://habr.com/ru/post/1500839/


All Articles