最近我一直在排练Sprite Kit,我遇到了一个很奇怪的问题。当缩放父节点(改变缩放比例)时,由SKPhysicsJointPin连接在一起的物体逐渐彼此分开,然后关节断开。让我给你看看这些图像。缩放时接头断裂
这是正常状态:
这里放大时'S:
在这里,缩小时是:
如果你问我如何加入机构:我加盟棕色粘在蓝色节点中心的蓝色节点上。任何想法我的问题是什么?
编辑:我最近发现,关节不会中断,一切工作如预期当连接的身体不动态。因此,例如,如果我使用[SKPhysicsBody bodyWithEdgleLoopFromRect]而不是 [SKPhysicsBody bodyWithRectangleOfSize]为精灵创建物理主体,则没有任何问题。但我需要身体是动态的。
下面是我用来将物理附加到节点的代码。当然,这一切都是动态完成的。为了简洁,我只是硬编码。
-(void)attachPhysics{
//fixedComponentLeft & fixedComponentRight are two SKSprites
fixedComponentLeft.physicsBody=[SKPhysicsBody bodyWithCircleOfRadius:fixedComponentLeft.frame.size.width];
fixedComponentRight.physicsBody=[SKPhysicsBody bodyWithCircleOfRadius:fixedComponentLeft.size.width];
beam1.physicsBody=[SKPhysicsBody bodyWithRectangleOfSize:beam1.size];
joiningBody.physicsBody=[SKPhysicsBody bodyWithCircleOfRadius:joiningBody1.size.width];
[self.scene.physicsWorld addJoint:[SKPhysicsJointPin jointWithBodyA:fixedComponentLeft.physicsBody bodyB:beam1.physicsBody anchor:fixedComponentLeft.position]];
[self.scene.physicsWorld addJoint:[SKPhysicsJointPin jointWithBodyA:joiningBody.physicsBody bodyB:beam1.physicsBody anchor:beam1.endPoint]];
beam2.physicsBody=[SKPhysicsBody bodyWithRectangleOfSize:beam2.size];
[self.scene.physicsWorld addJoint:[SKPhysicsJointPin jointWithBodyA:joiningBody.physicsBody bodyB:beam2.physicsBody anchor:beam2.position]];
[self.scene.physicsWorld addJoint:[SKPhysicsJointPin jointWithBodyA:fixedComponentRight.physicsBody bodyB:beam2.physicsBody anchor:beam2.endPoint]];
}
在上面的代码中,beam1和beam2是SKSpriteNode的子类的实例。默认情况下,锚点是(0,0.5),我添加了一个名为endPoint的属性,它作为精灵最右边的边缘点。
谢谢@Andrew的洞察力。我已经添加了一些代码。 –
您是否在设置锚点位置时尝试使用[yourScene convertPoint:fromNode:]? – Andrew
我刚刚做了你的建议后,其实我可能以前试过。但它并没有帮助 –