1

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?

4

2 に答える 2

4

他の誰かがこれに出くわした場合に備えて、私はそれを理解しました.

  1. 初期化では、デバッグ描画オブジェクトを作成します (GLESDebugDraw は Cocos2d+Box2d に付属しています)。
  2. フラグを設定して、描画するもの (形状、重心、関節など) を指定します。
  3. それをワールド オブジェクトに割り当てます。

b2Draw *debugDraw = new GLESDebugDraw(PTM_RATIO);

debugDraw->SetFlags(GLESDebugDraw::e_shapeBit);

_world->SetDebugDraw(debugDraw);

次に、トリックは、 ccLayer の draw メソッドをオーバーライドして呼び出す必要があることです。

_world->DrawDebugData();

draw メソッドになければなりません。そうしないと、これは機能しません。最初に、自分のスケジュールされたメソッド (_world->step() を呼び出す場所) に入れようとしましたが、うまくいきませんでした。

于 2012-10-20T18:53:57.143 に答える
0

in coco2dx v2.2 これは次のように行われます

//これをinit()に書く

_debugDraw = new GLESDebugDraw(PTM_RATIO);
  _world->SetDebugDraw(_debugDraw);


  uint32 flags = 0;
  flags += b2Draw::e_shapeBit;
  flags += b2Draw::e_jointBit;
  flags += b2Draw::e_aabbBit;
  flags += b2Draw::e_pairBit;
  flags += b2Draw::e_centerOfMassBit;
  _debugDraw->SetFlags(flags);

///////////////////////////////////////////////

void HelloWorld::draw() {

CCLayer::draw();

CC_ENABLE_BOX2D_INTEGRATIONの場合

ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );

kmGLPushMatrix();

_world->DrawDebugData();

kmGLPopMatrix();

終了

}

Application.mk ファイルがある場合はチェックインします。

APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1

次にそれを置き換えます

APP_CPPFLAGS := -frtti -DCC_ENABLE_BOX2D_INTEGRATION=1 -DCOCOS2D_DEBUG=1

于 2013-10-31T08:18:00.503 に答える