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):
- Write an
detectSpaceShipCollisionWithCoins
method in which we will enumerate the coin objects.- (void)detectSpaceShipCollisionWithCoins { [self enumerateChildNodesWithName:@"Coin" usingBlock: ^(SKNode *node, BOOL *stop...