原文链接:http://blog.csdn.net/zhangxaochen/article/details/8016456
看这里: http://is.gd/VoBVUJ
开启DebugDraw的方法比较简单,步骤如下:
1. 包含 GLES-Render.h 头文件(在类似这样的路径下:C:\cocos2d-2.0-x-202\samples\TestCpp\Classes\Box2DTestBed\GLES-Render.h),同时把GLES-Render.cpp 加入工程;
2. 加入这样的代码:
GLESDebugDraw* debugDraw=new GLESDebugDraw(PTM_RATIO);
_world->SetDebugDraw(debugDraw);
uint32 flags=0;
flags+=b2Draw::e_shapeBit;
debugDraw->SetFlags(flags);
然后把他加到_world 里面;
顺便记得设定绘制模式。(如果不设定,默认m_drawFlags 值为零,即看不到画的东西)
----------------------------------------------
那么,这些flags都有什么模式呢?
在b2Draw.h 里面看到 :
enum
{
e_shapeBit = 0x0001, ///< draw shapes
e_jointBit = 0x0002, ///< draw joint connections
e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
e_pairBit = 0x0008, ///< draw broad-phase pairs
e_centerOfMassBit = 0x0010 ///< draw center of mass frame
};
一般情况下肯定要 e_shapeBit, 这样会有个粉红色的几何图形:
e_aabbBit 是说,绘制“轴向的外边框”,像这样:
e_centerOfMassBit显然是绘制质心位置,就是那个红绿两道杠:
另外, e_pairBit,知识有限,不懂什么是 “broad-phase pairs”,希望有前辈能够赐教下~~
原文链接:http://blog.csdn.net/zhangxaochen/article/details/8016456
{{OVER}}