如何使用Coco2d-x 3.0 beta 2启用Box2d调试绘图 [英] How to enable Box2d debug draw with Coco2d-x 3.0 beta 2

查看:110
本文介绍了如何使用Coco2d-x 3.0 beta 2启用Box2d调试绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Cocos2d-x 3.0启用调试绘图?有一些代码可以在cocos2d-x 2.0上实现,但它们甚至都不能在Cocos2d-x上编译。不幸的是,我对cocos2d-x和Box2d都是陌生的,我不知道如何移植它们。如果您将共享如何绘制形状的方法,那将很棒。

How I should enable debug draw with Cocos2d-x 3.0? There are some codes that do that with cocos2d-x 2.0 but they don't even compile on Cocos2d-x. Unfortunately I am new to both cocos2d-x and Box2d and I don't know how to port them. That would be great if you would share the method how you draw shapes.

编辑:

我发现

http:// blog.csdn.net/tian2kong/article/details/20386213

我已覆盖抽奖我的应用程序的主要方法 Layer 像这样:

I have overridden the draw method of my applications main Layer like this:

void HelloWorld::draw()
{
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION);
    kmGLPushMatrix();
    m_world->drawDebugData();
    kmGLPopMatrix();
}

而且还这样做:

GLESDebugDraw *debugDraw = new GLESDebugDraw(PTM_RATIO);
m_world.SetDebugDraw(debugDraw);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
/*
flags += b2Draw::e_jointBit;
flags += b2Draw::e_centerOfMassBit;
flags += b2Draw::e_aabbBit;
flags += b2Draw::e_pairBit;
*/
debugDraw->SetFlags(flags);

而且有效!但是,当我将子对象添加为child时,形状保持不变。

And it worked! But when I addChild a sprite, the shapes stay blow my sprites. How to bring them front?

推荐答案

打开焦点并搜索GLES-Render.cpp。该文件将位于cocos2dx文件夹中的路径中。打开封闭的文件夹,然后将文件GLES-Render.h和GLES-Render.cpp拖到项目中。
然后在init方法中添加以下代码

Open spotlight and search for GLES-Render.cpp. This file will be there in a path in the cocos2dx folder. Open the enclosing folder and drag the files GLES-Render.h and GLES-Render.cpp to the project. Then add the following code in the init method

b2Draw *m_debugDraw = new  GLESDebugDraw(PTM_RATIO);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
flags += b2Draw::e_jointBit;
flags += b2Draw::e_aabbBit;
flags += b2Draw::e_pairBit;
flags += b2Draw::e_centerOfMassBit;
m_debugDraw->SetFlags(flags);
H_world->SetDebugDraw(m_debugDraw); 

然后添加绘制方法。

void HelloWorld::draw()
{
kmGLPushMatrix();
H_world->DrawDebugData();
kmGLPopMatrix();
}

别忘了包含GLES-Render.h

Don't forget to include GLES-Render.h

这篇关于如何使用Coco2d-x 3.0 beta 2启用Box2d调试绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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