Cocos2d + Box2d - 如何调试/显示身体? [英] Cocos2d + Box2d - how to debug/show bodies?
问题描述
我使用Cocos2d(2.0)和随其打包的Box2d创建了一个非常简单的设置。我在我的世界有几个身体,但没有sprites与他们连接,我想调试他们的方向,位置等。
这似乎是一个漂亮的标准任务,但我不知道如何轻松地做到这一点。从我的研究,它似乎与这些方法相关:
_world-> SetDebugDraw
_world-> DrawDebugData(...);
//和GLES-Render类别
帮助?
$ b $- 设置标记以指定要绘制的内容(形状,重心,关节等)。
- 将其分配给世界对象。
li>在初始化时,你想创建一个调试绘图对象
(GLESDebugDraw自带Cocos2d + Box2d)。
b2Draw * debugDraw = new GLESDebugDraw(PTM_RATIO);
debugDraw-> SetFlags(GLESDebugDraw :: e_shapeBit);
_world-> SetDebugDraw(debugDraw);
然后,诀窍是你需要重写 ccLayer的绘图方法并调用:
_world-> DrawDebugData();
p>
它必须在绘制方法中,否则这将不工作。我最初试图把它放在我自己的计划方法(我调用_world-> step()),这不工作。
I've created a pretty simple setup using Cocos2d (2.0) and Box2d that comes packaged with it. I have a few bodies in my world, but don't have sprites linked up with them yet and I want to debug their orientations, positions, etc.
This seems like a pretty standard task, but I could not find out how to do this easily. From my research it seems related to these methods:
_world->SetDebugDraw(...);
_world->DrawDebugData(...);
// and the GLES-Render class
Help?
I figured it out in case anyone else stumbles across this.
- In your initialization, you want to create a debug draw object (GLESDebugDraw comes with Cocos2d+Box2d).
- Set the flags to specify what you want drawn (shapes, center of gravity, joints, etc.).
- Assign it to your world object.
b2Draw *debugDraw = new GLESDebugDraw(PTM_RATIO);
debugDraw->SetFlags(GLESDebugDraw::e_shapeBit);
_world->SetDebugDraw(debugDraw);
Then, the trick is that you need to override ccLayer's draw method and call:
_world->DrawDebugData();
It must be in the draw method otherwise this won't work. I initially tried to put it in my own scheduled method (where I call _world->step()) and this did not work.
这篇关于Cocos2d + Box2d - 如何调试/显示身体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!