Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
2015-03-01 13:39
405 查看
void PhysicsFixedUpdate::onEnter()
{
PhysicsDemo::onEnter();
_scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
_scene->getPhysicsWorld()->setGravity(Point::ZERO);
// wall
auto wall = Node::create();
wall->setPhysicsBody(PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size, PhysicsMaterial(0.1f, 1, 0.0f)));
wall->setPosition(VisibleRect::center());
this->addChild(wall);
addBall();
scheduleOnce(schedule_selector(PhysicsFixedUpdate::updateStart), 2);
}
void PhysicsFixedUpdate::addBall()
{
auto ball = Sprite::create("Images/ball.png");
ball->setPosition(100, 100);
ball->setPhysicsBody(PhysicsBody::createCircle(ball->getContentSize().width/2, PhysicsMaterial(0.1f, 1, 0.0f)));
ball->getPhysicsBody()->setTag(DRAG_BODYS_TAG);
ball->getPhysicsBody()->setVelocity(Point(1000, 20));
this->addChild(ball);
}
void PhysicsFixedUpdate::updateStart(float delta)
{
addBall();
//重点在这里
_scene->getPhysicsWorld()->setAutoStep(false);
scheduleUpdate();
}
void PhysicsFixedUpdate::update(float delta)
{
// use fixed time and calculate 3 times per frame makes physics simulate more precisely.
//这里表示先走3步瞧瞧 如果fps是1/60 三个setp就是1/180
for (int i = 0; i < 3; ++i)
{
_scene->getPhysicsWorld()->step(1/180.0f);
}
}
{
PhysicsDemo::onEnter();
_scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
_scene->getPhysicsWorld()->setGravity(Point::ZERO);
// wall
auto wall = Node::create();
wall->setPhysicsBody(PhysicsBody::createEdgeBox(VisibleRect::getVisibleRect().size, PhysicsMaterial(0.1f, 1, 0.0f)));
wall->setPosition(VisibleRect::center());
this->addChild(wall);
addBall();
scheduleOnce(schedule_selector(PhysicsFixedUpdate::updateStart), 2);
}
void PhysicsFixedUpdate::addBall()
{
auto ball = Sprite::create("Images/ball.png");
ball->setPosition(100, 100);
ball->setPhysicsBody(PhysicsBody::createCircle(ball->getContentSize().width/2, PhysicsMaterial(0.1f, 1, 0.0f)));
ball->getPhysicsBody()->setTag(DRAG_BODYS_TAG);
ball->getPhysicsBody()->setVelocity(Point(1000, 20));
this->addChild(ball);
}
void PhysicsFixedUpdate::updateStart(float delta)
{
addBall();
//重点在这里
_scene->getPhysicsWorld()->setAutoStep(false);
scheduleUpdate();
}
void PhysicsFixedUpdate::update(float delta)
{
// use fixed time and calculate 3 times per frame makes physics simulate more precisely.
//这里表示先走3步瞧瞧 如果fps是1/60 三个setp就是1/180
for (int i = 0; i < 3; ++i)
{
_scene->getPhysicsWorld()->step(1/180.0f);
}
}
相关文章推荐
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题------沈大海
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
- cocos2d-x lua 物理引擎,速度过快导致的刚体穿透,穿越边界问题
- 关于cocos2d-X 3.x版本使用引擎自带的物理引擎Physics
- 实例介绍Cocos2d-x物理引擎:HelloPhysicsWorld
- Ubuntu 11.10中如何解决:Gtk-WARNING ___ 无法在模块路径中找到主题引擎:“pixmap”问题
- cocos2d-x3.0开发笔记 物理引擎封装Physics深入学习
- cocos2d-x 3.0开发笔记---物理引擎封装 Physics深入学习
- cocos2d-x 之 CCPhysicsSprite 基于物理引擎的Sprite
- 大约cocos2d-X 3.x使用引擎版本自带的物理引擎Physics
- cocos2d-x3.0 Physics新的物理引擎
- [cocos2d-x3.3]cocostudio的Button按钮触发两次回调函数问题解决
- 关于Cocos2d-x中物理世界的物体乱跳的问题的解决
- Cocos2d-x 3.0 Lua编程 之 响应物理引擎的Contact事件回调不执行的问题
- cocos2d-x 之 CCPhysicsSprite 基于物理引擎的Sprite
- quick-cocos2d-x3.3中player3打开黑屏问题(已解决)
- linux 安装VMware问题解决-解决ubuntu上VMware: Gtk-WARNING **: 无法在模块路径中找到主题引擎:“murrine
- quick-cocos2d-x 中自带物理引擎 PhysicsMaterial 恢复力的问题