本文整理汇总了C++中PhysicsBody::setVelocityLimit方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsBody::setVelocityLimit方法的具体用法?C++ PhysicsBody::setVelocityLimit怎么用?C++ PhysicsBody::setVelocityLimit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsBody
的用法示例。
在下文中一共展示了PhysicsBody::setVelocityLimit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupPhysics
void SinglePlayerScene::setupPhysics()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
float visibleHeight = visibleSize.height;
PhysicsWorld* world = this->getScene()->getPhysicsWorld();
world->setGravity(Vec2(0, (visibleHeight / 320.0f) * -98.0f));
world->setSpeed(GAME_SPEED);
world->setDebugDrawMask(DEBUGDRAW_OPTIONS);
Vec2 takyanPos = _takyan->getPosition();
PhysicsBody *takyanBody = PhysicsBody::createCircle(_takyan->getContentSize().width * BALL_RADIUS, PhysicsMaterial(0.01f, 1.0f, 1.0f)); //_takyan->getPhysicsBody();
float takyanMass = takyanBody->getMass();
float velocityLimit = takyanMass * 150.0f;
takyanBody->setMass(takyanMass * 100.0f);
takyanBody->setRotationEnable(false);
takyanBody->setVelocityLimit(velocityLimit);
_takyan->setPhysicsBody(takyanBody);
PHYSICS_MASK(takyanBody, MASK_TAKYAN, MASK_BOUNDS | MASK_KICKER, MASK_BOUNDS | MASK_KICKER);
Size takyanSize = _takyan->getContentSize();
takyanSize.height *= 0.8f;
PhysicsMaterial material(0.0025f, 0.0f, 1.0f);
PhysicsBody *takyanTailBody = PhysicsBody::createCircle(takyanSize.width, material);
takyanTailBody->setMass(takyanMass * 0.01);
takyanTailBody->setRotationEnable(false);
takyanTailBody->setLinearDamping(1.0f);
takyanTailBody->setVelocityLimit(velocityLimit * 0.5f);
_takyanTail->setPhysicsBody(takyanTailBody);
PHYSICS_MASK(takyanTailBody, MASK_TAKYAN_TAIL, 0, MASK_FLOOR);
Vec2 diff = _takyanTail->getPosition() - _takyan->getPosition();
Vec2 anch1 = Vec2::ANCHOR_MIDDLE;
Vec2 anch2 = Vec2::ANCHOR_MIDDLE;
auto jointS = PhysicsJointLimit::construct(takyanBody, takyanTailBody, anch1, anch2, 0, diff.y);
jointS->setCollisionEnable(false);
world->addJoint(jointS);
PhysicsBody *kickerBody = PhysicsBody::createCircle(_kicker->getContentSize().width * KICKER_RADIUS, PhysicsMaterial(1.0f, 1.0f, 1.0f)); //_kicker->getPhysicsBody();
kickerBody->setDynamic(false);
kickerBody->setEnable(false);
_kicker->setPhysicsBody(kickerBody);
PHYSICS_MASK(kickerBody, MASK_KICKER, MASK_TAKYAN, MASK_TAKYAN);
int takyans = MASK_TAKYAN | MASK_TAKYAN_TAIL;
auto floorBody = PhysicsBody::createBox(_floorBounds->getContentSize(), PhysicsMaterial(1.0f, 0.3f, 0.7f)); //_floorBounds->getPhysicsBody();
floorBody->setDynamic(false);
_floorBounds->setPhysicsBody(floorBody);
PHYSICS_MASK(floorBody, MASK_BOUNDS, takyans, takyans);
auto ceilingBody = PhysicsBody::createBox(_ceilingBounds->getContentSize(), PhysicsMaterial(1.0f, 0.3f, 0.7f));
ceilingBody->setDynamic(false);
_ceilingBounds->setPhysicsBody(ceilingBody);
PHYSICS_MASK(ceilingBody, MASK_BOUNDS, MASK_TAKYAN, MASK_TAKYAN);
Size wallSize = _leftWallBounds->getContentSize();
wallSize.height *= 5.0f;
auto leftWallBody = PhysicsBody::createBox(wallSize); //_leftWallBounds->getPhysicsBody();
leftWallBody->setDynamic(false);
_leftWallBounds->setPhysicsBody(leftWallBody);
PHYSICS_MASK(leftWallBody, MASK_WALLS, takyans, MASK_TAKYAN);
auto rightWallBody = PhysicsBody::createBox(wallSize); //_rightWallBounds->getPhysicsBody();
rightWallBody->setDynamic(false);
_rightWallBounds->setPhysicsBody(rightWallBody);
PHYSICS_MASK(rightWallBody, MASK_WALLS, takyans, MASK_TAKYAN);
}