後面我用cocos2dx V3.8,併成功借鑑的東西與覆蓋得出這樣的:我怎麼能借鑑的東西精靈精靈不
void Box2dManager::draw(Renderer *renderer, const Mat4& transform, uint32_t flags){
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION);
Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
box2dWorld->DrawDebugData();
Director::getInstance()->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
// super::draw(renderer, transform, flags);
}
但它總是背後的精靈。它在修改z順序後不能更改。
解決
現在我能處理的cocos2d 3.x版的Box2D DrawDebugData問題。 我粘貼所有的cocos2dx解決代碼。 V2(簡單,因爲V2引擎的OpenGL平局是每個單一任務)
void Box2dManager::draw(){
ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position);
kmGLPushMatrix();
box2dWorld->DrawDebugData();
kmGLPopMatrix();
}
V3(V3引擎推動平局commond與quence核心,所以你需要創建一個回調)
void Box2dManager::draw(Renderer *renderer, const Mat4& transform, uint32_t flags){
super::draw(renderer, transform, _transformUpdated);
GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION);
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(Box2dManager::onDraw, this);
renderer->addCommand(&_customCommand);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void Box2dManager::onDraw() {
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 oldMV;
oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV);
box2dWorld->DrawDebugData();
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV);
}
refrence: http://discuss.cocos2d-x.org/t/box2d-debug-drawing-for-cocos2d-x-3-0/11912/2 http://blog.csdn.net/zszeng/article/details/50000757
我不得不使用'_customCommand.init(_globalZOrder + 1);'到初始化第e自定義渲染命令,否則Box2d相關的東西會呈現在精靈之後。任何想法熱解決這個?我正在使用cocos2d-x 3.10。 – rraallvv