2011-07-27 7 views
0

간단한 게임에서 나는 동전과 다른 물건을 집어 넣기 위해 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]; 

     } 
    } 
} 

답변

0

당신이 불규칙한 모양을 필요하면 개인적으로 Box2D의 및 PhysicsEditor을 추천 할 것 : 여기

는 코드입니다. 그것은 약간의 학습 곡선 (Box2D)을 가지고 있지만, 대부분의 용도에있어 가치가 있습니다.

Box2D (although it comes with Cocos2D and has a template built in)

PhysicsEditor (not free, but I recommend it as the program is very easy to use and the developer is a kind man)

그것은 물리학 시뮬레이션뿐만 아니라. 원하는 경우 충돌 감지에만 사용할 수 있습니다.

Box2D For Just Collision Detection

0

내가 CGPath와 함께이 문제를 해결 : 레이 Wenderlich의 사이트는 단지에 대한 좋은 자습서를 가지고있다.

이 자습서는 나를 도왔습니다 http://bobueland.com/cocos2d/?p=134

관련 문제