我正在尝试在后台线程上加载和初始化我的场景,以便它在加载时不会暂停 4 秒。它工作得很好,有一个例外:我无法让 SKPhysicsJointPin -addJoint 工作 - 它每次都会崩溃,但前提是它在线程上被调用。
关节设置如下:
SKPhysicsJointPin* pin =[SKPhysicsJointPin jointWithBodyA:base.physicsBody bodyB:lever.physicsBody anchor:pt];
[gameScene.physicsWorld addJoint:pin]; // this crashes on a thread!
我正在像这样进行后台加载:
gSceneBeingLoaded = self; // keep a strong ref while loading so that we don't release the object prematurely
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
{
/* LOAD SCENE ON BACKGROUND THREAD */
[gSceneBeingLoaded loadSceneData];
/* SHOW SCENE ON MAIN THREAD */
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[gSceneBeingLoaded presentScene];
gSceneBeingLoaded = nil; // release the extra reference
});
});
就像我说的那样,一切都很好,除了每次都会崩溃的调用,但只有在线程上时才会崩溃。