2013-08-21 34 views
0

我一直在爲此掙扎數星期,這讓我瘋狂。如何註冊點擊CCSprite,但忽略圖像的透明部分?

我能夠檢測到常規精靈被點擊的時間,我的最終目標是在屏幕上拖動特定的精靈。這是針對iOS6或更高版本的,我正在爲背景信息製作通用應用程序,因此它將在iPhone,iPad和每個版本的視網膜上運行。屏幕上還會同時出現多個精靈。

我想要的只是能夠在我的精靈上註冊一個點擊,如果它位於它的非透明部分。如果我點擊精靈的透明區域,點擊應該被忽略,除非它下面有一些其他的精靈,在這種情況下點擊應該跟隨它。

我在網上找到的所有例子都無法爲我工作,我相信這是由於iOS6中發生的glReadPixels變化引起的。

如果有人會提供一些指導目前的鏈接或代碼片段,我會非常感激!

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
NSLog(@"Touches Began! %i",[self.sprites count]); 

CGPoint location = [self convertTouchToNodeSpace: [touches anyObject]]; 

for (CCSprite *tempSprite in self.sprites) 
{ 
    //Increase the size of bounding box.. 
    CGRect rect=tempSprite.boundingBox; 
    rect.size.height=rect.size.height + 20; 
    rect.size.width=rect.size.width + 20; 

    if (CGRectContainsPoint(rect, location)) 
    { 
     NSLog(@"sprite touched %i",tempSprite.zOrder); 
     _currentSprite = tempSprite; 

     //so how how do I test the pixel of the sprite they touched to see if it was transparent that will work in iOS6???? 



    } 
} 

}

+0

這裏是我用來實現像素完美的觸感http://www.learn-cocos2d.com/2011/12/fast-pixelperfect-collision-detection-cocos2d-code-1of2一個非常有用的文章/ –

回答