Learn iOS SpriteKit with Examples, Code Snippets and Video Tutorials

Swipe Gesture Recognizers with Sprite Kit and Swift

Swipe Gesture Recognizers with Sprite Kit and Swift
October 12, 2014 Justin
unrecognized selector sent to instance

To See the UPDATED Version for Swift 3, click here.

Here’s a quick snippet of Swift and Sprite Kit code for those of you that need it. Below we set up four functions, one for each direction, to handle whatever we want to happen when the user swipes the screen in those directions.  Then in the didMoveToView statement, we create the UISwipeGestureRecognizer variables for each direction and add them to the view. Notice the action: Selector part of each calls their respective functions.

Don’t forget to add the colon after the function name (for example, “swipedDown:”), or you might get the ol’ unrecognized gesture sent to instance crash.

Optionally you could add some extra properties to any of the UISwipeGestureRecognizer variables. For example…

…Now the swipeRight gesture requires 2 fingers to be touching the screen.

That’s all for now.  Just remember folks, if you die outside of your own game, you don’t regenerate… Ever.

Justin Dike is the owner and lead developer at CartoonSmart.com. He's taught hundreds of hours of game development video tutorials, covering everything from coding to art. These days he's working mostly on Swift and Sprite Kit tutorials, which often lead into highly polished iOS / tvOS Starter Kits, which require no programming at all, but are capable of making nearly any type game! Yeah, you read that write. You can also find Justin at the official CartoonSmart Podcast


Leave a reply

Check out our premium Swift and Sprite Kit Tutorial content!

Visit CartoonSmart.com