您的位置:首页 > 移动开发 > Cocos引擎

Cocos2d-x Box2D debugDraw

2014-04-04 10:42 381 查看
高人就谈不上了,最近开始学cocos2d-x,前天刚刚做了个东西,正好需要加入debugDraw,和你分享下经验吧
1 cocos2d中testcpp->box2dTestBed文件夹,下面有GLES-Render.h/GLES-Render.cpp,这两个文件先要拷到你的项目中
2 在你的helloworldscene.h中创建  GLESDebugDraw *m_DebugDraw 对象 再写个 void draw()方法
3 在helloworldscene.cpp中 init()函数里:
 //PTM_RATIO是box2d中单位米和像素转换比率 #define PTM_RATIO 32
 void  HelloWorld2::setupDebugDraw()

{

 m_debugDraw = new GLESDebugDraw(PTM_RATIO);

world->SetDebugDraw(m_debugDraw);

        uint32 flags = 0;

        flags += b2Draw::e_shapeBit;

        flags += b2Draw::e_jointBit;

        flags += b2Draw::e_aabbBit;

        flags += b2Draw::e_pairBit;

        flags += b2Draw::e_centerOfMassBit;

        m_debugDraw->SetFlags(flags);

}

void HelloWorld2::draw()

{

     //

    // IMPORTANT:

    // This is only for debug purposes

    // It is recommend to disable it

    CCLayer::draw();

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

    kmGLPushMatrix();

    world->DrawDebugData();

    kmGLPopMatrix();

    CHECK_GL_ERROR_DEBUG();

},

这些就可以画出刚体了,但好像不会绘制关节,还有就是如果你的刚体上加图片了,刚体绘制会被遮挡到图片后面 也许也会露出一点点边框能看到,那就这样了,祝你成功!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: