2011-07-27 6 views
0

私の簡単なゲームでは、コインやその他のものをピッキングするのにboundingBoxを使用しますが、Sprite(Alphaなし)の不規則な領域検出が必要です。 boundingBoxの代替手段はありますか?あなたが不規則な形状を必要とする場合、私は個人的にBOX2DとPhysicsEditorをお勧めします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)を持っていますが、ほとんどの用途には十分な価値があります。

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

関連する問題