【发布时间】:2010-05-23 06:27:40
【问题描述】:
如何判断您是否触摸了 CCLabel?
下面的代码显然不够好,因为它只测试点相等。自然接触点不一定等于 CCLabel (CCNode) 的位置属性。如何判断触摸点是否落在“矩形”内? 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");
}
}
}
【问题讨论】:
标签: iphone xcode opengl-es cocos2d-iphone