CC UITouches无视第二次触摸

时间:2012-01-19 03:55:04

标签: ios xcode cocos2d-iphone uitouch

我正在尝试使用UITouch移动一个精灵,我需要处于多点触控模式,因为我有一个按钮,我也需要在我移动精灵的时候点击。

问题是当我错过了按钮并且用我的另一根手指击中屏幕时,第二根手指变为触摸开始,这导致我的精灵跳跃位置。 任何解决方法。我尝试按钮在自己的班级,但这没有帮助。 之所以我不只是将所有代码都移动到触摸中是因为我正在计算触摸开始的偏移量。

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];
    switch ([allTouches count]) {
        case 1:{
            NSLog(@"moving touch 1");}break;

所以现在发生的事情就是当我将手指移过屏幕时 它检测到移动1但是一旦我放在第二根手指上它停止移动1 我不希望它停止移动1

2 个答案:

答案 0 :(得分:0)

-touchesBegan:方法中,您是否正在测试触摸点以查看它是否在图像中?

答案 1 :(得分:0)

在按钮触摸上设置条件,并且不包括任何其他情况,以避免其他触摸。

喜欢:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count]) {
        case 1: {
            CGPoint pos = [[[allTouches allObjects] objectAtIndex:0] locationInView:self];
            // code here for single touch.


        } break;
        case 2: {
            //get out two fingers
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            // code here for multi touch

        } break;

    }


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    NSSet *allTouches = [event allTouches];

    switch ([allTouches count])
    {
        case 1: { //Move
            //Single touch


        } break;
        case 2: { //Zoom
            //multi touch

            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];

            // Code according to you


        } break;

    } 

}

希望这会有所帮助。

相关问题