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:(,
}
}
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