Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been stuck with collisions in Cocos2d-x and Box2D for the past few days.

I have a class object: Ball

enum{

kActionIdle,
kActionBigger,
kActionCollision
}
Ball
{
    //variable
      m_actionState = kActionState ;
      bool m_collision;

//method
     startContact()  
     {
        if(m_actionState == kActionState)// i think it can't check this condition althought its' true
        sprite->runAction(action);//this line run normally if add in other function
     }

}
class MyContactListener : public b2ContactListener

  {
    void BeginContact(b2Contact* contact) {

      //check if fixture A was a ball
      void* bodyUserData = contact->GetFixtureA()->GetBody()->GetUserData();
      if ( bodyUserData )
        static_cast<Ball*>( bodyUserData )->startContact();

      //check if fixture B was a ball
      bodyUserData = contact->GetFixtureB()->GetBody()->GetUserData();
      if ( bodyUserData )
        static_cast<Ball*>( bodyUserData )->startContact();

    }

In method tick() of Box2D :

void tick(cctime dt)
{
    for(std::vector <Ball*>::iterator i = m_listBall->begin(); i!=m_ListBall->end(); i++) //this for run normally 
   {
     (*i)->startContact(); //i add breakpoint in here, and call function startContact, but not run action:(,
   }
}
share|improve this question
Can you expand on the problem you're having? startContact() is being called but not doing what you expect? Tell us what you've tried already. (Help us help you). – Byte56 Mar 15 at 15:13
Yes,i have two ball, so when they collide each other, i want ball action (bigger). but it's not doing. i've tried touch on ball to bigger and it works, but when collide each other not – user919496 Mar 15 at 15:44
Have you stepped through your code to verify the contact listener is actually dispatching the correct contact function calls? The contact listener needs to be correctly registered with the world before it will function. – Evan Mar 16 at 14:33
i registered contact listerner with world@_@ – user919496 Mar 17 at 4:10

closed as too localized by bummzack, Sean Middleditch, Trevor Powell, Byte56, Josh Petrie Mar 27 at 13:59

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.