Adding the Controls

You can now add some rudimentary controls so that the hero is able to move around when a player touches the screen. You could do this by using the accelerometer, and you could also do it by using screen tapping or swiping. In this case, you will use screen tapping for now. Add the following code to the bottom of your viewDidLoad method, and note that it includes some commented code for handling swipes in two different directions:

let gestureRecognizers = NSMutableArray()let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")tapGesture.numberOfTouchesRequired = 1let twoTapGesture = UITapGestureRecognizer(target: self, action: "handleTwoTap:")twoTapGesture.numberOfTouchesRequired ...

Get Learning Swift™ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.