複製TestCpp的GLES-Render.h和GLES-Render.cpp過來。函數
添加一個成員變量:ui
GLESDebugDraw *m_debugDraw;
初始化物理引擎的時候:debug
void HNGameLayer::initPhysics() { m_debugDraw = new GLESDebugDraw(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); m_b2World = new b2World(b2Vec2(0, -10)); m_b2World->SetAllowSleeping(true); // 容許物體進入休眠狀態 m_b2World->SetContinuousPhysics(true); // 使用連續物理碰撞檢測 m_b2World->SetDebugDraw(m_debugDraw); ....其餘代碼 }
重寫draw函數調試
void HNGameLayer::draw() { CCLayer::draw(); if (!m_bDebug) { return; } ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); kmGLPushMatrix(); m_b2World->DrawDebugData(); kmGLPopMatrix(); CHECK_GL_ERROR_DEBUG(); }
防止被背景阻擋了。由於draw函數話出來的東西的z-order應該是0,把背景的z-order設成負數就能夠了code