2-star challenge: colliding puppets

Before going further, you need to add the code that detect collisions between the rabbit and the puppet. When this happens, the blinking action should be run as well as the sound that is played when the rabbit collides with the wrong door. Also, you should take into account that colliding with the enemies will not affect the score.

Solution

I've decided to use a different flag to detect whether a collision with an enemy happened, as we will need it later in this chapter. So, let's add a new variable declaration at the top of GameScene:

private var isEnemyCollisionDetected: Bool = false

Then, we need to write the code that detects these collisions. So, add the following block of code at the end of detectCollisions ...

Get Getting Started with SpriteKit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.