A Closer Look at Physics Bodies

There are two types of physics bodies: volume-based bodies and edge-based bodies, which are illustrated in the images that follow.

images/WorkingWithPhysicsAndCollisionDetection/bodies.png

To create these physics bodies, you use the SKPhysicsBody class and one of its initializers. Typically, you’ll use an initializer that matches your sprite node’s shape, such as a rectangle, circle, polygon, or custom path. You then assign this physics body to the node’s physicsBody property, like so:

 ball.physicsBody = ​SKPhysicsBody​(circleOfRadius: ball.frame.width/2)

When defining shapes, always consider performance. A circle is the most efficient shape, whereas a path-based polygon ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.