We apply physics simulation to the bodies by adding the SKPhysicsBody
function to a node. While the scene processes each frame, it performs all the physics-related calculations for all the bodies in the scene. It also calculates all the custom forces that are applied on any body in the scene, which eventually gives the realistic effects in the game. Collision detection is an important part while developing any game in the real world because in almost all games we check for the collision of two bodies. For example, in any warfare game, we may need to check whether a bullet has collided with the player.
There are various shapes for the physics bodies that can be used to apply physics to a scene. These shapes are defined as the personal space of the node. When the shape of one node intersects with the shape of another node, the -didBeginContact
method is invoked and physics may be applied. Now, to implement the collision detection, we will have to...