为此,在特定对象类中检查哪个夹具与对象碰撞。 如果它与我的自动播放器机身匹配。然后我给跳转命令。
所以跳跃并不顺利。因为碰撞后跳了起来。我需要在物体到达之前跳跃,这样跳跃在屏幕上看起来会很好。
关于如何在cocos2dx box2d中做什么?
我在公路街区类中的跳转代码
bool Block::HandleBeginContact(b2Fixture *fixtureA,b2Fixture *fixtureB)
{
b2Body *bodyA = fixtureA->GetBody();
b2Body *bodyB = fixtureB->GetBody();
b2Fixture *myFixture = RoadBlock->GetFixtureList(); //am getting all list from Road block body
if(myFixture == fixtureA || myFixture == fixtureB)
{
//am collided with Road block
if(bodyB == AIRider::g_MainBody || bodyA == AIRider::g_MainBody )
{
AIBike::Direction.y = 50.0f;
}
}
}
答案 0 :(得分:1)
创建您自己的矩形对象,根据需要调整框大小
box.SetAsBox(2.0f, 2.5f);
。并将其放置在交通信号灯,道路拦截器,速度制动器等硬物之前。
那就是那里你可以检查碰撞和跳跃。确保传感器已开启。bool yourinvisiblebox2dobject::HandleBeginContact(b2Fixture *fixtureA,b2Fixture *fixtureB)
{
b2Body *bodyA = fixtureA->GetBody();
b2Body *bodyB = fixtureB->GetBody();
b2Fixture *myFixture = RoadBlock->GetFixtureList(); //am getting all list from Road block body
if(myFixture == fixtureA || myFixture == fixtureB)
{
//am collided with Road block
if(bodyB == AIRider::g_MainBody || bodyA == AIRider::g_MainBody )
{
AIBike::Direction.y = 50.0f;
}
}
}