Book Image

Game Development with Swift

By : Stephen Haney
Book Image

Game Development with Swift

By: Stephen Haney

Overview of this book

Table of Contents (18 chapters)
Game Development with Swift
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 7. Implementing Collision Events

So far, we have let the SpriteKit physics simulation detect and handle collisions between game objects. You have seen that Pierre Penguin sends enemies and coins flying off into space when he flies into them. This is because the physics simulation automatically monitors collisions and sets the post-collision trajectory and velocity of each colliding body. In this chapter, we will add our own game logic when two objects come into contact: taking damage from enemies, granting the player invulnerability after touching the star, and tracking points as the player collects coins. The game will become more fun to play as the game mechanics come to life.

The topics in this chapter include:

  • Learning the SpriteKit collision vocabulary

  • Adding contact events to our game

  • Player health and damage

  • Collecting coins

  • The power-up star logic