I am trying to connect two SKSpriteNodes together in a scene with a SKPhysicsJointLimit. One node is not effected by the physics simulation, and the other is. This should result in the motion of a pendulum. However, when an SKPhysicsJointLimit is used to connect the nodes seems to create three anchor points.
The can be seen here https://i.stack.imgur.com/E5r26.jpg the green node is not effected by the physics simulation.
// set scene up
self.anchorPoint = CGPointMake(0.5, 0.5);
self.backgroundColor = [SKColor grayColor];
self.view.showsPhysics = YES;
// set up the two bodies to be connected
SKSpriteNode* testSpriteOne = [[SKSpriteNode alloc] initWithColor:[SKColor yellowColor] size:NODE_SIZE];
testSpriteOne.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:NODE_SIZE];
testSpriteOne.position = CGPointMake(-20, -10);
testSpriteOne.physicsBody.dynamic = YES;
[self addChild:testSpriteOne];
SKSpriteNode* testSpriteTwo = [[SKSpriteNode alloc] initWithColor:[SKColor greenColor] size:NODE_SIZE];
testSpriteTwo.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:NODE_SIZE];
testSpriteTwo.position = CGPointMake(93, 166);
testSpriteTwo.physicsBody.dynamic = NO;
[self addChild:testSpriteTwo];
// set up the joint
SKPhysicsJointLimit* ropeJoint = [SKPhysicsJointLimit jointWithBodyA:testSpriteTwo.physicsBody bodyB:testSpriteOne.physicsBody anchorA:testSpriteTwo.position anchorB:testSpriteOne.position];
[self.physicsWorld addJoint:ropeJoint];
My scene's anchor point is (0.5, 0.5), but if it is set to (0, 0) the physics simulation works, but is not in the right position. The other workaround solution is to create temporary alternate positions that are offset by the scaled width and height of the scene and use those in the creation of the joint. The code below shows this.
// works with offset
CGPoint AlternatePosition1 = CGPointMake(testSpriteOne.position.x + self.scene.size.width * self.scene.anchorPoint.x, testSpriteOne.position.y + self.scene.size.height * self.scene.anchorPoint.y);
CGPoint AlternatePosition2 = CGPointMake(testSpriteTwo.position.x + self.scene.size.width * self.scene.anchorPoint.x, testSpriteTwo.position.y + self.scene.size.height * self.scene.anchorPoint.y);
SKPhysicsJointLimit* ropeJoint = [SKPhysicsJointLimit jointWithBodyA:testSpriteOne.physicsBody bodyB:testSpriteTwo.physicsBody anchorA:AlternatePosition1 anchorB:AlternatePosition2];
First, I'm not sure why this works. The resulting points are not in the scene coordinates. Also, this "solution" will not work if for example the sprites are contained in a world node and the world node is changing its position in the scene. Even when the nodes positions in the scene are used in SKPhysicsJoint.
So, is there any way to have SKPhysicsJointLimit function properly in a scene with an anchor of (0.5,0.5) without having to offset the position of the nodes.