Game Development Reference
In-Depth Information
GFPhysicsCategorySquare;
head.physicsBody.collisionBitMask =
GFPhysicsCategoryWorld;
[scene addChild:head];
//Pinning Rectangle and Square
NSLog(@"Head position %@",
NSStringFromCGPoint(head.position));
SKPhysicsJointSpring* pin =[SKPhysicsJointSpring
jointWithBodyA:backBone.physicsBody
bodyB:head.physicsBody anchorA:head.position
anchorB:CGPointMake(backBone.position.x,
backBone.position.y+backBone.size.height/2.0)];
pin.damping = 0.5;
pin.frequency = 0.5;
[scene.physicsWorld addJoint:pin];
}
To apply a spring joint between two physics bodies, we have provided two phys-
ics bodies along with two anchor points as the function parameters. We can also
provide additional parameters such as damping and frequencies.
13. Now, replace the createSlidingJointOnScene function call with cre-
ateSpringJointOnScene . Add the following code at the end of the init
function:
[self createSpringJointOnScene:self];
14. Now compile and run the project and you should be able to see both the physics
bodies sliding over each other.
15. Our next type of joint is the limit joint in our sample project. Now open the
GameScene.m file and add the following function at the end of the file:
Search WWH ::




Custom Search