我试图在后台线程上加载和初始化我的场景,以便它在加载时不会暂停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
});
});
就像我说的,一切都很好,除了一个调用,每次都会崩溃,但只有在一个线程。
这可能会解决addJoint:
的问题SKPhysicsJointPin* pin =[SKPhysicsJointPin jointWithBodyA:base.physicsBody bodyB:lever.physicsBody anchor:pt];
GameScene *gameScene = (GameScene*)self.scene;
[gameScene.physicsWorld addJoint:pin];
我昨晚发现的另一个结论。希望对别人有用。dispatch_async NOT帮助我。
如果你创建了一个POINT (SKShapeNode by path 1x1)并想要pin它-这在iOS8中是不可能的
3x3 -好的。该死的