Game Development Reference
In-Depth Information
5. Now as we have removed the gravity to make the object fall freely, it's important
to create a boundary around the world, which will hold all the objects of the
world and prevent them to go off the screen. Add the following line of code to
add the invisible boundary around the screen to hold the physics objects:
// 1 Create a physics body that borders the screen
SKPhysicsBody* gameborderBody = [SKPhysicsBody
bodyWithEdgeLoopFromRect:self.frame];
// 2 Set physicsBody of scene to borderBody
self.physicsBody = gameborderBody;
// 3 Set the friction of that physicsBody to 0
self.physicsBody.friction = 0.0f;
In the first line, we are are creating an edge-based physics boundary object, with a
screen size frame. This type of a physics body does not have any mass or volume
and also remains unaffected by force and impulses. Then we associate the object
with the physics body of the scene. In the last line we set the friction of the body
to 0, for a seamless interaction between objects and the boundary surface. The fi-
nal file should look something like the following screenshot:
Search WWH ::




Custom Search