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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.