How do you detect touches in a CCScene on Cocos2D V3?

cocos2d-iphone, ios, objective-c, touch

Solution

Looks like all I had to do was:

In the CCScene constructor, enable touches:

[self setUserInteractionEnabled:YES];

Add the touchBegan method in:

- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    NSLog(@"touchBegan");
}

Ta-da! Much easier in V3 than in V2!

Optionally, can also:

[self setMultipleTouchEnabled:YES];

Problem

I know that you used to be able to do it through: ``` <CCLayerObject>.isTouchEnabled = YES; ``` ...in conjunction with a registration to the touch dispatcher: ``` -(void)registerWithTouchDispatcher { [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; } ``` ...and then just get the callbacks: ``` -(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { CGPoint point = [self convertTouchToNodeSpace:touch]; NSLog(@"X:%ftY:%f", point.x, point.y); } ``` But what do you need to do in V3?

Original source

Related problems