在CCLayer的子类中,有以下两种方法:
-(void)setupDebugDraw
{
_debugDraw = new GLESDebugDraw(PTM_RATIO * [[CCDirector sharedDirector] contentScaleFactor]);
world->SetDebugDraw(_debugDraw);
uint32 flags = 0;
flags += b2DebugDraw::e_shapeBit;
flags += b2DebugDraw::e_jointBit;
flags += b2DebugDraw::e_aabbBit;
flags += b2DebugDraw::e_pairBit;
flags += b2DebugDraw::e_centerOfMassBit;
_debugDraw->SetFlags(flags);
// (TEST CODE) BELOW DOESN'T SHOW!
_debugDraw->DrawPoint(b2Vec2(0,0), 500.0f, b2Color(255, 255, 255));
}
-(void) draw {
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if (world) {
// BODIES SHOW OK
world->DrawDebugData();
// (TEST CODE) BELOW DOESN'T SHOW EITHER!
_debugDraw->DrawPoint(b2Vec2(0,0), 500.0f, b2Color(255, 255, 255));
}
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
在上面的代码中,有两个测试代码,两个都没有显示任何内容。
Xcode 4.3.2 IOS模拟器5.1 Box2D 2.1.2
经过一番尝试: _debugDraw-> DrawPoint(b2Vec2(0,0),50.0f,b2Color(255,0,0)); //没有画 _debugDraw-> DrawPoint(b2Vec2(1,1),50.0f,b2Color(255,0,0)); //有画!!
似乎与一个或多个0的绘制点根本不会绘制!即使尺寸足够大!
void GLESDebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
{
glColor4f(color.r, color.g, color.b,1);
glPointSize(size);
GLfloat glVertices[] = {
p.x * mRatio, p.y * mRatio
};
glVertexPointer(2, GL_FLOAT, 0, glVertices);
glDrawArrays(GL_POINTS, 0, 1);
glPointSize(1.0f);
}
因为我不懂openGL API,所以这里有什么东西?
答案 0 :(得分:0)
debug draw的zindex为0,所以如果你的精灵有一个zindex> 0你不会看到你的调试画。