SKPhysicsBody
A node's physicsBody
property uses the SKPhysicsBody
class object. In the life cycle of a frame, the didSimulatePhysics
function is called just after actions are evaluated. The work of this function is to calculate the physical properties, such as gravity, velocity, friction, restitution, collision, or other forces. After these calculations are done, the positions and orientations of nodes are updated in the update
function. If we are going to apply some force on a node, it is necessary that we assign the SKPhysicsBody
object to that node first.
Sprite Kit provides us with two kinds of physics bodies:
- Volume-based: These are the kind of physics bodies that have mass and volume
- Edge-based: These are the kind of physics bodies that don't have mass and volume
In volume-based bodies, we can control if it should be affected by gravity, friction, collision, and so on, by setting it as static
or dynamic
. This property is very useful as we can make a static platform or a moving...