How to tell if you touched a CCLabel?
The following code obviously does not work well enough because it only tests for point equality. Naturally touch point will not necessarily be equal to the position property of the CCLabel (CCNode). How to I tell if a Touch point has fallen within the "rectangle?" of the CCLabel?
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
self.myGraphManager.isSliding = NO;
if(CGPointEqualToPoint(location, label1.position)){
NSLog(@"Label 1 Touched");
}else if(CGPointEqualToPoint(location, label2.position)){
NSLog(@"Label 2 Touched");
}else if(CGPointEqualToPoint(location, label3.position)){
NSLog(@"Label 3 Touched");
}else if(CGPointEqualToPoint(location, label4.position)){
NSLog(@"Label 4 Touched");
}else if(CGPointEqualToPoint(location, label5.position)){
NSLog(@"Label 5 Touched");
}else if(CGPointEqualToPoint(location, label6.position)){
NSLog(@"Label 6 Touched");
}
}
}