Game Development Reference
In-Depth Information
GFPhysicsCategorySquare;
head.physicsBody.collisionBitMask =
GFPhysicsCategoryWorld;
[scene addChild:head];
//Pinning Rectangle and Square
NSLog(@"Head position %@",
NSStringFromCGPoint(head.position));
SKPhysicsJointFixed* pin =[SKPhysicsJointFixed
jointWithBodyA:backBone.physicsBody
bodyB:head.physicsBody
anchor:CGPointMake(head.position.x-5,
head.position.y)];
[scene.physicsWorld addJoint:pin];
}
Now, we have attached two physics bodies together with a fixed joint. In the last
function, we have provided two bodies and the anchor point to which they are at-
tached.
5. Now, replace the createPinJointOnScene function call with cre-
ateFixedJointOnScene . Add the following code in the end of the init
function:
[self createFixedJointOnScene:self];
6. Now, compile and run the project and you should be able to see both the physics
bodies attached by the fixed joint. You will observe that the bodies are attached
together with the specified anchor point.
7. Now, to implement the sliding joint in our sample project, open the GameS-
cene.m file and add the following function at the end:
Search WWH ::




Custom Search