cocos2d识别手指的左右移动

在cocs2d中,怎样识别手指从右划向右的动作和从右划向左的动作?谢谢各位

在 ccTouchesBegan 中用全局变量存粗location的坐标,记为oriPoint,然后在ccTouchesMoved 中用location与oriPoint 比较
横坐标

哪个变量呢

在 ccTouchesBegan 中用全局变量存粗location的坐标,记为oriPoint,然后在ccTouchesMoved 中用location与oriPoint 比较
横坐标

//注册touch代理

  • (void)registerWithTouchDispatcher
    {
    addTargetedDelegate:self priority:0 swallowsTouches:NO];
    }

然后在ccTouchMoved方法里通过判断手指的移动距离来判断

  • (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
    {
    CGPoint location = ];
    location = convertToGL:location];
    CGPoint previousLocation = ];
    previousLocation = convertToGL:previousLocation];
    CGFloat moved = location.x-previousLocation.x;
    CCLog(@“手指往%@滑动”, moved > 0 ? @“右” :@“左”);

}

十分感谢,这个方法有用

实际放到项目中,没起作用,坐标值为0,这是怎么回事

实际放到项目中,没起作用,坐标值为0,这是怎么回事,检测不到坐标啊

苹果有默认的手势识别,比如你想实现左滑 右滑 可以在appdelegate 的函数 applicationDidFinishLaunching 中实现如下代码

UISwipeGestureRecognizer *swipeGestureR =  initWithTarget:self action:@selector(handleSwipeGestureRight:)];
;
  openGLView] addGestureRecognizer:swipeGestureR];

;

UISwipeGestureRecognizer *swipeGestureL =  initWithTarget:self action:@selector(handleSwipeGestureLeft:)];
;
 openGLView] addGestureRecognizer:swipeGestureL];

;

handleSwipeGestureRight和handleSwipeGestureLeft 这两个函数自己可以随便定义,随便起名字,声明、实现 那么当向左滑的时候就会调用handleSwipeGestureLeft 函数,向右滑的时候就会调用handleSwipeGestureRight 函数,不过据说用这种方法会稍微影响按钮的相应时间,个人觉得用完之后直接使用 removeGestureRecognizer 删掉就好了