O'Reilly logo

Getting Started with SpriteKit by Jorge Jordán

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

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 ...

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