onContactBegin not working with cocos2d-x v3.0rc2

I’m trying to play around with cocos to teach myself a little about game programming and hopefully write my own simple game. The problem I’ve run in to is that I haven’t been able to get onContactBegin working. I’ve declared the method in my header and implemented the method in the cpp along with following the instructions here: http://www.cocos2d-x.org/docs/manual/framework/native/physics/physics-integration/en , on how to register the listener. I have the touch listeners working just fine so I’m a little stumped because it’s pretty much the same thing.

I feel like I’ve missed something incredibly simple. Any thoughts, suggestions fixes or general advice for future endeavors would be much appreciated.

Thanks

my problem’s the same,too!

The same with cocos2d-x v3 RC0 and RC1, my code:

auto contactListener = EventListenerPhysicsContact::create();
contactListener->onContactBegin = CC_CALLBACK_1(myClass::onContactBegin, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);

function onContactBegin now is:

myClass::onContactBegin(PhysicsContact &contact)
{
do Something ();// but this never happen
}

BUG??

@kiddi2202 This may be a bug, but as far as I can tell, this is a pretty major feature for custom interactions between physics bodies so feel like we must be missing something.

Hey!

I found the way to solved that problem.

You must write one more command line in your code,

this command:

objectBody->setContactTestBitmask(true); // <- exactly this line

after the command

auto objectBody = PhysicsBody::createCircle(mySrite->getContentSize().width / 2);

1 Like

Thanks. This really helps!

Is that really correct? setContactTestBitmask() does not take a boolean, but an int which is a bitmask. Cocos2d-x 3.x.

you should make one body setDynamic true

circlephysicsBody->setDynamic(true);
1 Like

oke , i think problem here