2012-10-09 21 views
0

我還需要HUDLayer和GameLayer中的觸摸檢測。
因爲當player.position> 480時,用戶無法正確地與GameLayer進行交互。
觸摸位置與HUDLayer相關,這很好,但我需要觸及兩個圖層。我嘗試使用ccTouchesBegan方法,在兩個圖層中都啓用了觸摸,但Log仍然顯示兩次相同的觸摸位置。我怎樣才能做到這一點?在HUDLayer和GameLayer中檢測觸摸

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); 
    } 
} 

回答

2

如果我理解你想要做什麼的權利,你只需要觸摸位置轉換爲節點空間

[layer convertToNodeSpace: glTouchLocation]; 
+0

完美。正是我需要的。哪裏谷歌讓我失望,你盛行:) – iamruskie