Game Development Reference
In-Depth Information
initWithColor:[SKColor grayColor] size:CGSizeMake(40,
40)];
head.position = CGPointMake(backBone.position.x,
backBone.position.y-40);
head.physicsBody = [SKPhysicsBody
bodyWithRectangleOfSize:head.size];
[scene addChild:head];
}
The preceding code will create two physics bodies, one rectangle and one square.
We have adjusted the bodies' positions relative to each other.
9. Now, add the following line of code at the end of the initWithSize method to
add the physics bodies in the game scene:
[self createPhysicsBodiesOnScene:self];
Here we are creating the bodies by calling the instance method inside
initWithSize .
10. Now, compile and run the app. You should be able to see the two physics bodies
created in the world and they will fall to the ground because of gravity. This will
look something similar to following screenshot:
Search WWH ::




Custom Search