Cocos2d + Box2d - 如何调试/显示身体? [英] Cocos2d + Box2d - how to debug/show bodies?

查看:23
本文介绍了Cocos2d + Box2d - 如何调试/显示身体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Cocos2d (2.0) 和随附的 Box2d 创建了一个非常简单的设置.我的世界中有一些实体,但还没有与它们关联的精灵,我想调试它们的方向、位置等.

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

帮助?

推荐答案

我想出来以防万一其他人偶然发现.

I figured it out in case anyone else stumbles across this.

  1. 在您的初始化中,您要创建一个调试绘图对象(GLESDebugDraw 自带 Cocos2d+Box2d).
  2. 设置标志以指定您想要绘制的内容(形状、重心、关节等).
  3. 将其分配给您的世界对象.

b2Draw *debugDraw = new GLESDebugDraw(PTM_RATIO);

debugDraw->SetFlags(GLESDebugDraw::e_shapeBit);

_world->SetDebugDraw(debugDraw);

那么,诀窍就是你需要重写ccLayer的draw方法并调用:

Then, the trick is that you need to override ccLayer's draw method and call:

_world->DrawDebugData();

它必须在 draw 方法中,否则这将不起作用.我最初尝试将它放在我自己的预定方法中(我在其中调用 _world->step()),但这没有用.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆