我还需要在HUDLayer和GameLayer中进行触摸检测 因为当player.position> 480,用户无法正确与GameLayer交互 触摸位置与HUDLayer相关,这很好,但我需要触摸两个层。我在两个图层中尝试了触摸启用的ccTouchesBegan方法,但Log仍然显示两次相同的触摸位置。我怎么能这样做?
GameLayer.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);
}
}
答案 0 :(得分:2)
如果我理解你想做什么,你只需要用
将触摸位置转换为节点空间[layer convertToNodeSpace: glTouchLocation];