Revert "Fix imgui draw frame cause drawNode Afterimage"

This commit is contained in:
halx99 2021-06-17 21:16:06 +08:00
parent 7d8fe551cc
commit 8b9d3ce3cd
1 changed files with 10 additions and 6 deletions

View File

@ -45,10 +45,15 @@ public:
_trackLayer->getEventDispatcher()->addEventListenerWithSceneGraphPriority(mouseListener, _trackLayer);
scene->addChild(_trackLayer, INT_MAX);
#endif
// add an empty sprite to avoid render problem
// const auto sp = Sprite::create();
// sp->setGlobalZOrder(1);
// sp->setOpacity(0);
// addChild(sp, 1);
/*
* There a 3 choice for schedule frame for ImGui render loop
* a. at visit/draw to call beginFrame/endFrame, but at ImGui loop, we can't delete/add game object to Scene directly, will cause damage iterator
* a. at visit/draw to call beginFrame/endFrame, but at ImGui loop, we can't game object and add to Scene directly, will cause damage iterator
* b. scheduleUpdate at onEnter to call beginFrame, at visit/draw to call endFrame, it's solve iterator damage problem, but when director is paused
* the director will stop call 'update' function of Scheduler
* And need modify engine code to call _scheduler->update(_deltaTime) even director is paused, pass 0 for update
@ -152,16 +157,15 @@ void ImGuiEXT::init()
ImGui::StyleColorsClassic();
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
eventDispatcher->addCustomEventListener(Director::EVENT_AFTER_DRAW, [=](EventCustom*) {
beginFrame();
endFrame();
});
eventDispatcher->addCustomEventListener(Director::EVENT_BEFORE_DRAW, [=](EventCustom*) { beginFrame(); });
eventDispatcher->addCustomEventListener(Director::EVENT_AFTER_VISIT, [=](EventCustom*) { endFrame(); });
}
void ImGuiEXT::cleanup()
{
auto eventDispatcher = Director::getInstance()->getEventDispatcher();
eventDispatcher->removeCustomEventListeners(Director::EVENT_AFTER_DRAW);
eventDispatcher->removeCustomEventListeners(Director::EVENT_AFTER_VISIT);
eventDispatcher->removeCustomEventListeners(Director::EVENT_BEFORE_DRAW);
ImGui_ImplCocos2dx_SetCustomFontLoader(nullptr, nullptr);
ImGui_ImplCocos2dx_Shutdown();