Swipe in SpriteKit
Use UISwipeGestureRecognizer in didMoveToView method
Example
SwipeMoveCharacter.h
@interface SwipeMoveCharacter : SKSpriteNode - (void)initGestures:(UIView *)view; @end
SwipeMoveCharacter.m
#import "SwipeMoveCharacter.h" @implementation SwipeMoveCharacter - (void)initGestures:(UIView *)view { // This should be called from didMoveToView // Add swipe Event here UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; swipeRight.direction = UISwipeGestureRecognizerDirectionRight; [view addGestureRecognizer:swipeRight]; UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; [view addGestureRecognizer:swipeLeft]; UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; swipeUp.direction = UISwipeGestureRecognizerDirectionUp; [view addGestureRecognizer:swipeUp]; UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; swipeDown.direction = UISwipeGestureRecognizerDirectionDown; [view addGestureRecognizer:swipeDown]; } - (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateRecognized) { switch(recognizer.direction) { case UISwipeGestureRecognizerDirectionUp: break; case UISwipeGestureRecognizerDirectionDown: break; case UISwipeGestureRecognizerDirectionLeft: break; case UISwipeGestureRecognizerDirectionRight: break; } } } @end
Set all directions up, down, right, left.