How to enable Box2d debug draw with Coco2d-x 3.0 beta 2

后端 未结 4 1496
清酒与你
清酒与你 2021-01-27 05:07

How I should enable debug draw with Cocos2d-x 3.0? There are some codes that do that with cocos2d-x 2.0 but they don\'t even compile on Cocos2d-x. Unfortunately I am new to both

4条回答
  •  逝去的感伤
    2021-01-27 06:00

    For Debug Draw You Need Two File

    File Download Link

    After that

    Inclue that file

    and create a Vaiable in .h file

    GLESDebugDraw *debugDraw;

    and in .ccp file

    b2Vec2 gravity;
    gravity.Set(0.0f, -9.8f);
    this->world = new b2World(gravity);
    
    this->debugDraw = new GLESDebugDraw(PTM_RATIO);
    this->world->SetDebugDraw(debugDraw);
    
    
    uint32  flags  =  0 ;
    flags +=  b2Draw::e_shapeBit ;
    flags += b2Draw::e_jointBit;
    // flags + = b2Draw :: e_aabbBit;
    // flags + = b2Draw :: e_pairBit;
    flags += b2Draw::e_centerOfMassBit;
    this->debugDraw->SetFlags (flags);
    

    in . h file

    void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags);

    in .cpp

    void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
    {
        Layer::draw(renderer, transform, flags);
        Director* director = Director::getInstance();
        GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION );
        director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
        world->DrawDebugData();
        director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    }
    

    NOW Enjoy Debug draw

提交回复
热议问题