2012-03-07 13 views
0

私はcocos2dとbox2dでiphoneアプリを作っていますが、私は問題を抱えています。私はこのアプリケーションを非常にひどく必要とするため、b2ContactListenerの使い方についてこのチュートリアルに従っています... http://www.raywenderlich.com/505/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-22私は2つのオブジェクトが衝突するb2contactlistener issues

私はゲームで何をしているのかというだけではなく、b2contactlistenerをどう使うのかが分かりにくいのです。私のコード内でそのチュートリアルで

これは、衝突のためにすべての時間をチェックしますので、私は私のダニメソッドを更新する方法です

-(void) update: (ccTime) dt 
{ 
int32 velocityIterations = 8; 
int32 positionIterations = 1; 

// Instruct the world to perform a single step of simulation. It is 
// generally best to keep the time step and iterations fixed. 
world->Step(dt, velocityIterations, positionIterations);  


std::vector<MyContact>::iterator pos; 
for(pos = _contactListener->_contacts.begin(); 
    pos != _contactListener->_contacts.end(); ++pos) { 
    MyContact contact = *pos; 

    if ((contact.fixtureA == _bottomFixture && contact.fixtureB == _ballFixture) || 
     (contact.fixtureA == _ballFixture && contact.fixtureB == _bottomFixture)) { 
     NSLog(@"Ball hit bottom!"); 
    } 
} 
} 

しかし、私はそれが私が変更しなければならないこれらの数行であると信じて...私の2 b2Bodies、eggBodyとlocations.platformで動作するようにそれを変更する方法を

を知らない...

それは_bottomFixtureと_ballFixtureは私が私のb2Bodiesプラグインだろうと思った...しかし_bottomFixtureもb2body

ないように:)私は誰を混同している場合任意のヘルプは、申し訳ありません素晴らしいことだ、今私が感じると言う

if ((contact.fixtureA == _bottomFixture && contact.fixtureB == _ballFixture) || 
     (contact.fixtureA == _ballFixture && contact.fixtureB == _bottomFixture)) { 
     NSLog(@"Ball hit bottom!"); 
    } 

質問を投稿するだけで、私はおかしなことを明確にします

答えて

1

_bottomFixtureはb2Fixtureオブジェクトです。

あなたは

bottomBody->CreateFixture(&_fixturedef); 

上記の行がb2Fixtureを返すことにより、身体のfixturedefを作成するときに、それが作成されます。 ので、あなたは通常、私たちはこのb2Fixtureオブジェクトを追跡しない

b2Fixture *_bottomFixture = bottomBody->CreateFixture(&_fixturedef); 

を書くことができます。しかし、衝突の検出には、それを使用する必要があります。