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

1-star challenge: check collisions accurately

We learned how to detect collisions thanks to the intersects method provided by CGRect, but in this way, the collision will be triggered as soon as the rabbit's ears touch the doors. Let's add another condition to the if statement in detectCollisions in order to take into account the rabbit's and door's frame position. Thus, the collision will only happen when the door reaches half the rabbit's frame. As shown in the following screenshot:

1-star challenge: check collisions accurately

Solution

This challenge is very easy and I hope you were able to solve it. To perform this check, you just need to add the following condition to the if statement:

&& ...

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