gpt4 book ai didi

cocos2d-iphone - 如何在后台线程中使用 CCBReader 加载 ccbi 文件?

转载 作者:行者123 更新时间:2023-12-01 02:23:20 25 4
gpt4 key购买 nike

我最近使用 CocosBuilder 来构建游戏的界面。我可以在主线程中加载 ccbi 文件没有任何问题。但是当我在后台线程中加载它时。我有一个黑色背景的空层/节点。所以我的问题是如何在后台线程中正确加载它们?

最佳答案

我找到了一个解决方案。我可以同时加载ccbi文件并运行加载动画。
不知道是否正确,但它对我有用。
这是代码。
在 Cocos2d 多线程测试示例中可以找到解决方案。

//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");
}
});

关于cocos2d-iphone - 如何在后台线程中使用 CCBReader 加载 ccbi 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18648792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com