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/windowfunc touchesMoved(touches:Set<NSObject>, withEvent event:UIEvent)
: This method is called whenever a user moves his finger on the view/windowfunc touchesEnded(touches:Set<NSObject>, withEvent event:UIEvent)
: This method is called whenever a user removes the finger from view/windowfunc...