如果我移动舞台,那么球会穿过舞台……如果舞台不移动,那么球就不会穿过舞台。如何设置不通过球?
这里是代码:
ball->addComponent(PhysicsBody::createCircle(ball->getContentSize().width*0.5f, PhysicsMaterial(10.0f,0.1,0.1)));
ball->getPhysicsBody()->setGravityEnable(true);
ball->getPhysicsBody()->setRotationEnable(false);
ball->getPhysicsBody()->setDynamic(true);
ball->getPhysicsBody()->setTag(BALL_BODYS_TAG);
ball->getPhysicsBody()->setCategoryBitmask(0x01);
ball->getPhysicsBody()->setCollisionBitmask(0x02);
ball->getPhysicsBody()->setMass(10);
阶段:
stage->addComponent(PhysicsBody::createBox(stage->getContentSize(), PhysicsMaterial(100.0f,0.1,0.1)));
stage->getPhysicsBody()->setGravityEnable(false);
stage->getPhysicsBody()->setTag(STEPS_BODYS_TAG);
stage->getPhysicsBody()->setMass(100);
stage->getPhysicsBody()->setDynamic(true);
舞台移动代码:
void GBStage::updateStage(float dt)
{
Vec2 pos = this->getPosition();
pos.y += sBridge->gameSpeed;
this->setPosition(pos); //Updating just sprite position
}
现在舞台向上移动,球掉落。但是球经过了舞台。如何在舞台上停留。我的代码有什么问题?
找到临时解决方案。现在我停止移动舞台精灵的位置。我使用setVelocity移动舞台。现在,球永远不会经过步骤。
this->getPhysicsBody()->setVelocity(sBridge->steps_Velocity);
但是在带有Box2D的Cocos2d-ObjC中,我们可以选择移动精灵位置并将精灵位置设置为物理物体。现在,在Cocos2d-x中,我们无法移动精灵并将其位置设置为body。如果有人知道可以将子画面的位置设置到物理物体上并且仍然可以通过子画面实现运动,那么请回答。