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();
},
这些就可以画出刚体了,但好像不会绘制关节,还有就是如果你的刚体上加图片了,刚体绘制会被遮挡到图片后面 也许也会露出一点点边框能看到,那就这样了,祝你成功!
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();
},
这些就可以画出刚体了,但好像不会绘制关节,还有就是如果你的刚体上加图片了,刚体绘制会被遮挡到图片后面 也许也会露出一点点边框能看到,那就这样了,祝你成功!
相关文章推荐
- Cocos2d-x Box2D debugDraw
- cocos2d-x box2d debugdraw
- Cocos2d-X Box2D中部分方法的重点理解
- Cocos2d-X Box2D内容讲解
- cocos2d-x Box2d物理引擎基础操作
- cocos2d-x box2d使用调试绘图
- cocs2d-x box2d debugdraw的显示层次问题
- Cocos2d-x Box2D debugDraw
- cocos2d-x 3.x box2d显示debugDraw
- cocos2d-x Box2D 简单例子
- cocos2d-x Box2d 入门例子
- Cocos2d-x Box2D物理引擎编译设置
- cocos2d-x box2d Demo讲解
- cocos2d-x box2d物理引擎深入研究 第一篇续
- cocos2d-x box2d物理引擎深入研究 第一篇之旋转关节详解(b2RevoluteJoint)
- cocos2d-x box2d 入门
- cocos2d-x box2d 开发环境
- cocos2d-x box2d物理引擎深入研究 第一篇之鼠标关节详解(b2MouseJoint)
- cocos2d-x box2d 简单物体(一)
- Cocos2d-x Box2d中实现刚体的移动