O'Reilly logo

iOS Game Development By Example by Samanyu Chopra

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

Adding controls in Sprite Kit

Adding controls in a Sprite Kit doesn't need any external predefined framework; we can implement the controls in Sprite Kit using the following methods:

  • Tapping
  • Gesture recognitions (swiping in any direction, pinching, rotating)
  • Moving sprites using the accelerometer

Let's discuss each of the preceding controls in detail and also how we can implement them in our game.

Node tapping and clicking

We have four override methods for handling touch events with a UIResponder class, which is part of UIKit provided by Apple. Let's learn about them:

  • func touchesBegan(touches:Set<NSObject>, withEvent event:UIEvent): This method is called whenever a user touches the view/window
  • func touchesMoved(touches:Set<NSObject>, withEvent event:UIEvent) ...

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