0
我試圖在代碼中加載幾個大型模型並顯示場景。一般來說,在屏幕上加載和顯示場景需要很長時間,因爲它需要從一個pod模型中提取大量資源。 所以,我想在主線程中填充第一個場景,並在其他線程中保留其他場景。但是,當我將我的零件代碼移動到單獨的線程時,它正在崩潰。這裏是我的示例代碼:Cocos3d:在單獨的線程或後臺線程中加載場景時發生崩潰:
-(void) loadFirstScene
{
CC3PODResourceNode* podRezNode = [CC3PODResourceNode nodeWithName: @"FirstModel"];
podRezNode.resource = [IntroducingPODResource resourceFromFile: @"FirstModel.pod"];
podRezNode.shouldCullBackFaces = NO;
podRezNode.location = cc3v(0.0, -10.0, 0.2);
podRezNode.isTouchEnabled = YES;
[self addChild: podRezNode];
[NSThread detachNewThreadSelector:@selector(loadScenesInThread) toTarget:self
withObject:nil];
}
// Crashing if i add the below function in separate thread or background thread
-(void) loadScenesInThread
{
CC3PODResourceNode* podRezNode = [CC3PODResourceNode nodeWithName: @"SecondModel"];
podRezNode.resource = [IntroducingPODResource resourceFromFile: @"SecondModel.pod"];
podRezNode.shouldCullBackFaces = NO;
podRezNode.location = cc3v(0.0, -10.0, -5.0);
podRezNode.isTouchEnabled = YES;
[self addChild: podRezNode];
podRezNode = [CC3PODResourceNode nodeWithName: @"ThirdModel"];
podRezNode.resource = [IntroducingPODResource resourceFromFile: @"ThirdModel.pod"];
podRezNode.shouldCullBackFaces = NO;
podRezNode.location = cc3v(0.0, -10.0, -5.0);
podRezNode.isTouchEnabled = YES;
[self addChild: podRezNode];
// .. do more
}
有人可以指導我如何處理這種情況?
您能否指出我在哪裏可以看到「異步」方法的示例? – Getsy
在api文件中檢查CCTextureCache。不知道cocos3d是否提供這樣的方法。 – LearnCocos2D