I've been rehearsing Sprite Kit lately and I've come across a very strange problem. When zooming (changing the scale of) the parent node, bodies that are joined together by SKPhysicsJointPin separate from each other gradually and then joints break. Let me show you the images.
This is for the normal state:
Here's when zoomed in:
And here's when zoomed out:
If you ask how I join bodies: I join the brown sticks to the blue nodes on the center of the blue nodes. Any ideas what my problem is?
EDIT: I've recently found out that joints don't break and everything works as expected when the joining bodies are not dynamic. So for example, if I use [SKPhysicsBody bodyWithEdgleLoopFromRect] instead of [SKPhysicsBody bodyWithRectangleOfSize] to create physics body for a sprite, there's no problem. But I need the bodies to be dynamic.
Here's the code that I use to attach physics to nodes. Of course it's all done dynamically. I just hard coded for brevity.
-(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]];
}
On the above code, beam1 and beam2 are instances of subclass of SKSpriteNode. By default the anchor point is (0,0.5) and I've added a property called endPoint which serves as the rightmost edge point on the sprite.