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
m_DebugDraw = new GLESDebugDraw(PTM_RATIO);
//m_World 是世界对象
m_World->SetDebugDraw(m_DebugDraw);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
m_DebugDraw->SetFlags(flags);
draw();
4 在helloworldscene.cpp中 定义刚写的void draw()方法
void HelloWorld::draw()
{
CCLayer::draw();
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
kmGLPushMatrix();
m_World->DrawDebugData();//这个是一定要写的 其他几句不知道啥意思 看别人代码抄的
kmGLPopMatrix();
CHECK_GL_ERROR_DEBUG();
}
2 在你的helloworldscene.h中创建 GLESDebugDraw *m_DebugDraw 对象 再写个 void draw()方法
3 在helloworldscene.cpp中 init()函数里:
//PTM_RATIO是box2d中单位米和像素转换比率 #define PTM_RATIO 32
m_DebugDraw = new GLESDebugDraw(PTM_RATIO);
//m_World 是世界对象
m_World->SetDebugDraw(m_DebugDraw);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
m_DebugDraw->SetFlags(flags);
draw();
4 在helloworldscene.cpp中 定义刚写的void draw()方法
void HelloWorld::draw()
{
CCLayer::draw();
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
kmGLPushMatrix();
m_World->DrawDebugData();//这个是一定要写的 其他几句不知道啥意思 看别人代码抄的
kmGLPopMatrix();
CHECK_GL_ERROR_DEBUG();
}