Cocos2d-x3.3 Physics物理引擎模組解決了剛體穿透問題,cocos2dx3.3

來源:互聯網
上載者:User

Cocos2d-x3.3 Physics物理引擎模組解決了剛體穿透問題,cocos2dx3.3

看代碼:

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

    }

}


類比駕駛2011不可以建立物理引擎physics engine instance could not be created

NVIDIA PhysX物理加速驅動9.10.0513版For WinXP/XP-64/Vista/Vista-64/Win7/Win7-64,更新包括:修正在Optimus PC上PhysX加速不能正常啟用的問題。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.