O'Reilly logo

iOS Game Programming Cookbook by Bhanu Birani, Chhavi Vaishnav

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

We have our game integrated with collectables. Let's see how the spaceship will collect these collectables that is, coins. In character animation, we will be doing the animations on the spaceship and the coins when they collide with each other.

Getting ready

Before moving on to the complex animations to be applied on the entities of the scene, the understanding of actions (that is, SKAction) and update function of scene (SKScene) has to be there. This is so that during updation we can detect the collision between the coin and the spaceship and do some animations on both of them.

How to do it…

The following are the steps involved in detecting the collision and animating both the entities (coin and spaceship):

  1. Write an detectSpaceShipCollisionWithCoins ...

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