Game Development Reference
In-Depth Information
self.PhysicsBody = [SKPhysicsBody
bodyWithEdgeLoopFromRect:self.frame];
self.physicsBody.friction = 0.0f;
6. In the first line, we are creating an edge-based physics boundary object with a
screen-size frame. This type of physics body does not have any mass or volume
and they also remain unaffected by forces and impulses. Then we associate the
object with the physics body of the scene. In the last line, we change the friction
of the body to 0, to make interaction between objects and the boundary surface
lossless.
7. Now we are all set to create physics bodies in the world. Add the following meth-
od just after the initWithSize method:
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
}
This is the update method that will be called in each frame of the game execution.
So all the actions that need regular updates will be coded inside this method.
8. It's time to create physics objects in the world. All the physics objects are referred
to as bodies. Now add the following method to create the bodies in the physics
world.
-(void)createPhysicsBodiesOnScene:(SKScene*)scene
{
//Adding Rectangle
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];
[scene addChild:backBone];
//Adding Square
SKSpriteNode* head = [[SKSpriteNode alloc]
Search WWH ::




Custom Search