Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题

Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题,第1张

概述void PhysicsFixedUpdate::onEnter() {     PhysicsDemo::onEnter();          _scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);     _scene->getPhysicsWorld()->setGravity(Point::ZER

voIDPhysicsFixedUpdate::onEnter()

{

PhysicsDemo::onEnter();

_scene->getPhysicsWorld()->setDeBUGDrawMask(PhysicsWorld::DEBUGDRAW_ALL);

_scene->getPhysicsWorld()->setGravity(Point::ZERO);

// wall

autowall =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);

}


voIDPhysicsFixedUpdate::addBall()

{

autoball =Sprite::create("Images/ball.png");

ball->setposition(100,100);

ball->setPhysicsBody(PhysicsBody::createCircle(ball->getContentSize().wIDth/2,0.0f)));

ball->getPhysicsBody()->setTag(DRAG_BODYS_TAG);

ball->getPhysicsBody()->setVeLocity(Point(1000,20));

this->addChild(ball);


voIDPhysicsFixedUpdate::updateStart(floatdelta)

//重点在这里

_scene->getPhysicsWorld()->setautoStep(false);

scheduleUpdate();

voIDPhysicsFixedUpdate::update(floatdelta)

{

// use fixed time and calculate 3 times per frame makes physics simulate more precisely.

//这里表示先走3步瞧瞧 如果fps是1/60 三个setp就是1/180

for(inti =0; i <3; ++i)

{

_scene->getPhysicsWorld()->step(1/180.0f);

}

}

总结

以上是内存溢出为你收集整理的Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题全部内容,希望文章能够帮你解决Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1043700.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存