好吧,对于初学者来说,如果您担心,您应该只关注性能,即您正在查看或测量(在设备上而不是模拟器上)一些不适当的响应时间。
我会避免检测涉及另一个节点的触摸——它可能会变得混乱,软件明智。当触摸位于检测节点关注的对象的位置时,我倾向于严格返回 YES(来自 ccTouchBegan)。当您返回 NO 时,调度程序会将触摸传递给其他处理程序(“在控制台下”),直到一个这样的 CCNode 咬住它。种如下:
- (void) onEnter{
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
[super onEnter];
}
- (void) onExit{
[[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];
[super onExit];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
if (!_visible || !_enabled) {
return NO;
}
CGPoint loc = [touch locationInView:touch.view];
loc = [[CCDirector sharedDirector] convertToGL:loc];
if ([self containsPoint:loc]) {
// do your thing here !
return YES;
}
return NO;
}
-(BOOL) containsPoint:(CGPoint) location {
// determine here whether this node should be handling
// this touch.
}