O'Reilly logo

Learning iOS 8 Game Development Using Swift by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Collision detection

Collision detection in 2D games is done using the intersectsNode function of the sprite class itself. We can check whether the current sprite is overlapping the other sprite. In the intersectsNode function of the current node, we pass in a node that we want to check for collision with the current node. If there is an intersection, the function will return true, if not, it returns false.

For checking collision, we will first check the collision between the enemy's bullets and the hero. If there is collision, then the game is over. Then we will check collision between the hero's rockets and the enemies. If we detect a collision, then we have to update the score.

Also, if the enemy goes beyond the left of the screen, the game is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required