在我的簡單遊戲中,我使用boundingBox
來拾取硬幣和其他東西,但我需要使用Sprite(不含Alpha)的不規則區域檢測。是否有替代boundingBox
?確定CCSprite的不規則區域
這裏是代碼:
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [touch locationInView:[touch view]];
CGPoint point = [[CCDirector sharedDirector] convertToGL:location];
curentPosition = point;
arrToDel = [[NSMutableArray alloc] initWithCapacity:0];
// Находим спрайт под касанием
if (CGRectContainsPoint([some boundingBox], curentPosition)) {
CCLOG(@"popal");
}
CCSprite *coin = nil;
for (Coins *coins in self.bugs) {
if (CGRectContainsPoint([coins boundingBox], curentPosition)) {
coin = coins; // нашли монету
}
}
if (coin != nil) {
NSMutableArray *checkList = [NSMutableArray arrayWithCapacity:0];
for (Coins *coins in self.bugs) {
if (CGRectIntersectsRect([coin boundingBoxInPixels], [coins boundingBox]) && coins != coin) {
[checkList addObject:coins];
}
}
int max = coin.zOrder;
for (Coins *b in checkList) {
if (b.zOrder > max)
max = b.zOrder;
}
if (max == coin.zOrder) {
[self removeChild:coin cleanup:YES];
podsciot++;
CCLOG(@"%i",podsciot);
[arrToDel addObject:coin];
for (Coins *coins in arrToDel) {
if (coins.type == kKey) {
coinsCount++;
CCLOG(@"SeriiZ --> %i", coinsCount);
}
[self.bugs removeObject:coin];
}
}
}