2012-03-31 52 views
0

我有一個大圖像(1024,1496)作爲我的圖層的背景圖像。於是我開始顯示圖像的按鈕。 在應用程序的時候我顯示圖像的頂部,以及一些CCSprites。無法檢測UItouch

id move = [CCMoveBy actionWithDuration:2 position:ccp(0,-746)]; 
[layer runAction:move]; 

我的問題是,我無法檢測CCSrites上的觸摸,因爲他們的位置保持不變。 (20,1200)和(1024,746)之間的UITouch。

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 

for(UITouch * touch in [event allTouches]){ 

    for (CCSprite *book in books) { 
     CGPoint location = [touch locationInView:touch.view]; 
     location = [[CCDirector sharedDirector] convertToGL:location]; 
     if (CGRectContainsPoint([book boundingBox], location)) 
      NSLog(@"Touch"); 
     else{ 
      NSLog(@"NO Touch");   } 
    } 

}

}

不知道如何解決這個問題?

回答

1

只需將精靈觸摸轉換爲世界座標。您可以通過計算基於縮放和精靈大小的屏幕位置,或者使用Cocos中的方法轉換爲世界座標來使用自己的方法執行此操作。我傾向於做前者。