In the previous section of this chapter, we learned the most important techniques to perform actions on nodes, namely movements. Now that everything is moving, we need a way to detect when the main character tries to cross a closed door (a wrong door) or an open one (a correct door).
Detecting and handling collisions is one of the main techniques in game development, as a vast percentage of games is founded upon enemies trying to hit our character in many different ways or the player trying to kill the enemies by shooting them, jumping at them, and so on. But, what is a collision?
In game development, a collision is an intersection between two or more elements in a scene. There are different ways to detect them, from the most basic's such as checking whether the area of the frame of each node intersects other nodes' frames, to the advanced ones such as making use of the physics engines that most of the games' engines (including SpriteKit) provide...