加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 20:27:59 所属栏目:百科 来源:网络整理
导读:void PhysicsFixedUpdate ::onEnter() { PhysicsDemo :: onEnter (); _scene - getPhysicsWorld ()- setDebugDrawMask ( PhysicsWorld :: DEBUGDRAW_ALL ); _scene - getPhysicsWorld ()- setGravity ( Point :: ZERO ); // wall auto wall = Node :: create

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

}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读