How do you know if you have contacted CCLabel?
The following code obviously does not work well enough, because it only checks for point equality. Naturally, the touch point will not necessarily equal the CCLabel (CCNode) property of the position. How do I know if the Touch point has fallen into the "rectangle?" from 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");
}
}
}
source
share