0

我还需要在 HUDLayer 和 GameLayer 中进行触摸检测。
因为当 player.position > 480 时,用户无法与 GameLayer 正常交互。
触摸位置与 HUDLayer 相关,这很好,但我需要在两个图层上都进行触摸。我在两层都尝试了启用触摸的 ccTouchesBegan 方法,但 Log 仍然显示相同的触摸位置两次。我怎样才能做到这一点?

游戏层.mm

- (void) ccTouchesBegan(NSSet *)touches withEvent:(UIEvent *)event
{
   for(UITouch *touch in touches ) {
      CGPoint location = [touch locationInView: [touch view]];
      location = [CCDirector sharedDirector] convertToGL: location];
      NSLog(@"Touch X: %f Y: %f", location.x, location.y);
   }
}
4

1 回答 1

2

如果我理解正确你想做什么,你只需要将触摸位置转换为节点空间

[layer convertToNodeSpace: glTouchLocation];
于 2012-10-09T16:13:33.720 回答