1.碰撞检测回调方法编译出错;
auto *listener = EventListenerPhysicsContact::create();
listener->onContactBegin = CC_CALLBACK_1(HelloWorld::onContactBegin,this);
在3.0rc版本中回调函数的参数变为一个,不能使用原来的两个参数;
bool HelloWorld::onContactBegin(PhysicsContact& contact)
{
auto spriteA = (Sprite*)contact.getShapeA()->getBody()->getNode();
auto spriteB = (Sprite*)contact.getShapeB()->getBody()->getNode();
return true;
}
2.回调方法不调用
添加如下代码:
PhysicsBody * body = PhysicsBody::createCircle(_ball->getContentSize().width/2);
PhysicsBody * body2 = PhysicsBody::createCircle(_ball->getContentSize().width/2);
body->setMass(1.0f);
body->setContactTestBitmask(0xFFFFFFFF);
body2->setMass(1.0f);
body2->setContactTestBitmask(0xFFFFFFFF);
Physics 碰撞检测回调方法出错或者没有效果解决方法,布布扣,bubuko.com
时间: 2024-12-05 03:21:34