void Cocos2dRenderManager::initialise() { CCDirector *pDirector = CCDirector::sharedDirector(); MYGUI_PLATFORM_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); MYGUI_PLATFORM_LOG(Info, "* Initialise: " << getClassTypeName()); CCSize s = pDirector->getWinSizeInPixels(); this->setPosition(0, 0); this->setContentSize(s); setViewSize(int(s.width), int(s.height)); // 绑定到cocos2d节点 pDirector->setNotificationNode(this); mInfo.pixWidth = s.width; mInfo.pixHeight = s.height; mVertexFormat = VertexColourType::ColourABGR; mUpdate = true; kmMat4 tmp; kmGLGetMatrix(KM_GL_PROJECTION, &tmp); kmMat4Inverse(&mMatrix, &tmp); MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully initialized"); mIsInitialise = true; CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(Cocos2dRenderManager::listenForeToBackground), EVENT_COME_TO_BACKGROUND, NULL); pDirector->getScheduler()->scheduleUpdateForTarget(this, kCCPriorityNonSystemMin, false); }
void Cocos2dRenderManager::shutdown() { MYGUI_PLATFORM_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); MYGUI_PLATFORM_LOG(Info, "* Shutdown: " << getClassTypeName()); CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->getScheduler()->unscheduleUpdateForTarget(this); // 注意 (maybe)CCNotificationCenter的生命周期在mainloop结束之前就结束了 CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVENT_COME_TO_BACKGROUND); // 解除与cocos2d节点的绑定 pDirector->setNotificationNode(NULL); destroyAllResources(); MYGUI_PLATFORM_LOG(Info, getClassTypeName() << " successfully shutdown"); mIsInitialise = false; }
//------------------------------------------------------------------------------ bool finishAndCleanup(CCScene * pInScene, CCScene * pOutScene) { // clean up pInScene->setVisible(true); pInScene->setPosition(ccp(0, 0)); pInScene->setScale(1.0f); pInScene->setRotation(0.0f); pInScene->getCamera()->restore(); pOutScene->setVisible(false); pOutScene->setPosition(ccp(0, 0)); pOutScene->setScale(1.0f); pOutScene->setRotation(0.0f); pOutScene->getCamera()->restore(); // Before replacing, save the "send cleanup to scene" CCDirector *director = CCDirector::sharedDirector(); director->setNotificationNode(pInScene); return director->isSendCleanupToScene(); }