Detect when UIGestureRecognizer is up, down, left and right Cocos2d

前端 未结 7 1449
闹比i
闹比i 2020-12-01 09:28

I have a CCSprite that I want to move around using gestures. Problem is I\'m completely new to Cocos2D. I want my sprite to perform one action when the gesture is up, anothe

7条回答
  •  时光说笑
    2020-12-01 10:02

    Add one UISwipeGestureRecognizer for each axe (horizontal and vertical):

    UISwipeGestureRecognizer *horizontalSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(action)];
    [horizontalSwipe setDirection:(UISwipeGestureRecognizerDirectionRight |
                               UISwipeGestureRecognizerDirectionLeft )];
    
    [self.view addGestureRecognizer:horizontalSwipe];
    
    UISwipeGestureRecognizer *verticalSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(action)];
    [verticalSwipe setDirection:(UISwipeGestureRecognizerDirectionUp |
                         UISwipeGestureRecognizerDirectionDown )];
    
    [self.view addGestureRecognizer:verticalSwipe];
    

提交回复
热议问题