간단한 게임에서 나는 동전과 다른 물건을 집어 넣기 위해 boundingBox
을 사용하지만 Sprite (알파가없는)의 불규칙 영역 감지를 사용해야합니다. 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];
}
}
}