Game Development Reference
In-Depth Information
12. Now we will head towards implementing the spring joint in our sample project.
Open the GameScene.m file and add the following function at the end of the
file:
-(void)createSpringJointOnScene:(SKScene*)scene
{
SKSpriteNode* backBone = [[SKSpriteNode alloc]
initWithColor:[UIColor whiteColor]
size:CGSizeMake(20, 200)];
backBone.position =
CGPointMake(CGRectGetWidth(self.frame)/2.0,
CGRectGetHeight(self.frame)/2.0);
backBone.physicsBody = [SKPhysicsBody
bodyWithRectangleOfSize:backBone.size];
backBone.physicsBody.categoryBitMask =
GFPhysicsCategoryRectangle;
backBone.physicsBody.collisionBitMask =
GFPhysicsCategoryWorld;
[scene addChild:backBone];
//Adding Square
SKSpriteNode* head = [[SKSpriteNode alloc]
initWithColor:[SKColor grayColor] size:CGSizeMake(40,
40)];
head.position = CGPointMake(backBone.position.x,
backBone.position.y+backBone.size.height/2.0+40);
head.physicsBody = [SKPhysicsBody
bodyWithRectangleOfSize:head.size];
head.physicsBody.categoryBitMask =
Search WWH ::




Custom Search