问题描述
- 添加了一个物理世界后(有重力),添加了一个带刚体的精灵,但精灵时不时会自己弹起来,为什么?
-
添加了物理世界并设置重力,并用一个空心盒子承载
auto scene = Scene::createWithPhysics();Vect gravity(0, -1000.0); scene->getPhysicsWorld()->setGravity(gravity); //开启测试模式 scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); auto visibleSize = Director::getInstance()->getVisibleSize(); //创建一个空心盒子刚体作为世界边界 auto body = PhysicsBody::createEdgeBox(Size(visibleSize.width,visibleSize.height-100),PHYSICSBODY_MATERIAL_DEFAULT,3); //body->setDynamic(false); // body->setContactTestBitmask(1); //body->getShape(0)->setRestitution(0); //创建一个节点,用来承载刚体,这样刚体就能参与到游戏的物理世界 auto node = Node::create(); node->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); node->setPhysicsBody(body); scene->addChild(node); auto layer = HelloWorld::create(); scene->addChild(layer,10);
然后给精灵设置了刚体,并把弹性设置为0
auto playerPhysicsBody = PhysicsBody::createBox(this->getContentSize());playerPhysicsBody->getShape(0)->setFriction(0); playerPhysicsBody->getShape(0)->setRestitution(0); playerPhysicsBody->setCategoryBitmask(1); playerPhysicsBody->setCollisionBitmask(1); playerPhysicsBody->setContactTestBitmask(1); this->setPhysicsBody(playerPhysicsBody);
精灵落下后,并不会弹起,可以过一会,我并不做任何操作,他自己会弹一下弹一下,有时高有时低,还会弹不见。
请问下该如何解决,我想让精灵没有弹性。
解决方案
http://www.zhihu.com/question/38069607
时间: 2024-10-28 11:32:52