Friday, January 21, 2011

Disabling Multi Touch in Cocos2D

If you have already experienced developing iPhone Apps, then I think you know how to disable multi touch. It is very simple, using Interface Builder.

In Cocos2D as there is no interface builder, you have to do it on your own in code. It may frustrate you if you don't know the method. It is quite simple though.

- (BOOL)ccTouchesBegan:(NSSet *)touches
 withEvent:(UIEvent *)event {
       NSSet *allTouches = [event allTouches];
       if(allTouches>1)
            return;
       //else your rest of the code  
}

Quite simple isn't it? You can use it in CCTouchesMoved or CCTouchesEnded also.

1 comment:

  1. This works beautifully, thanks! Just one small oversight (might have been intentional for the sake of brevity) but here it is...

    if( allTouches > 1 )

    should be

    if( [allTouches count] > 1 )

    ReplyDelete