ios - Cocos2dx : 落下的物理球通过舞台
问题描述
如果我移动舞台然后球通过舞台...如果舞台不移动那么球永远不会通过舞台..如何设置球不通过?
这是代码:
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 中,我们不能移动 sprite 并将其位置设置为 body。如果有人知道是否可以将精灵位置设置为物理身体并仍然使用精灵实现运动,请回答。
推荐阅读
- function - Haskell - 通过创建更高级别的函数来计算函数的总和
- jquery - $.post WordPress ajax 没有回应
- web-scraping - 为我的“=importXML”函数获取“#N/A”
- r - 如何在 igraph 包的 visIgraph 中制作的图形中添加带有过滤器颜色的标题?
- r - 将数据框拆分为列表,同时将列值保留为子列表名称
- sql - 从二维数组中删除一个非唯一值
- rest - 休息最佳实践:我应该遵循什么标准?
- qt - 如何在窗格中使用 Material.elevation 和 Radius?
- bash - 将子字符串添加到bash中的字符串
- ios - 连接 UISlider 和 UITextField 以选择正确的数据 - 贷款分期付款的简单计算器