First you need to register your scene to receive touch events. So set self.isTouchEnabled = YES
in the scene's -(id)init
method. Then add a method to the scene to register the touch dispatcher.
- (void)registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self
priority:0
swallowsTouches:YES];
}
The get the location from the UITouch
when the the scene gets a ccTouchBegan:withEvent:
message.
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
}
Finally, you can test the touched location against the label's position by looking at the label's bounding box.
if (CGRectContainsPoint([label boundingBox], location)) {
// The label is being touched.
}