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

前端 未结 7 1382
闹比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:06
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGesture.direction = UISwipeGestureRecognizerDirectionUp|UISwipeGestureRecognizerDirectionDown;
    [self.gestureAreaView addGestureRecognizer:swipeGesture];
    [swipeGesture release];
    
    -(void)handleSwipeGesture:(UISwipeGestureRecognizer *) sender 
    {
        //Gesture detect - swipe up/down , can't be recognized direction
    }
    
    or
    
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;
    [self.view addGestureRecognizer:swipeGesture];
    [swipeGesture release];
    
    UISwipeGestureRecognizer *swipeGesture2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGesture2.direction = UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeGesture2];
    [swipeGesture2 release];
    
    -(void)handleSwipeGesture:(UISwipeGestureRecognizer *) sender 
    {
        //Gesture detect - swipe up/down , can be recognized direction
        if(sender.direction == UISwipeGestureRecognizerDirectionUp)
        {
        }
        else if(sender.direction == UISwipeGestureRecognizerDirectionDown)
        {
        }
    }
    
    0 讨论(0)
提交回复
热议问题