cocos2d-x学习日志(18) --程序是如何开始运行与结束?(3)

来源:未知 责任编辑:责任编辑 发表时间:2015-01-01 13:14 点击:


从 CCApplication 到 CCDirector

cocos2d-x 程序已经运行起来了,我们继续下一步,mainLoop 函数:
CCDirector* CCDirector::sharedDirector(void)
{
    if (!s_SharedDirector)
    {
        s_SharedDirector = new CCDisplayLinkDirector();
        s_SharedDirector->init();
    }

    return s_SharedDirector;
}

void CCDisplayLinkDirector::mainLoop(void)
{
    if (m_bPurgeDirecotorInNextLoop)
    {
        m_bPurgeDirecotorInNextLoop = false;
        purgeDirector();
    }
    else if (! m_bInvalid)
     {
         drawScene();
     
         // release the objects
         CCPoolManager::sharedPoolManager()->pop();        
     }
}
游戏的运行以场景为基础,每时每刻都有一个场景正在运行,其内部有一个场景栈,遵循后进后出的原则,当我们显示的调用 end() 方法,或者弹出当前场景之时,其自动判断,如果没有场景存在,也会触发 end() 方法,以说明场景运行的结束,而游戏如果没有场景,就像演出没有了舞台,程序进入最后收尾的工作,通过修改变量 m_bPurgeDirecotorInNextLoop 促使在程序 mainLoop 方法之内调用 purgeDirector方法。

走到最后一步,看 CCEGLView 是如果负责收尾工作的:
void CCEGLView::end()
{
    if (m_hWnd)
    {
#if(_MSC_VER >= 1600)
        if(m_bSupportTouch)
		{
		    s_pfUnregisterTouchWindowFunction(m_hWnd);
		}
#endif /* #if(_MSC_VER >= 1600) */
        DestroyWindow(m_hWnd);
        m_hWnd = NULL;
    }
    s_pMainWindow = NULL;
    UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
    delete this;
}

end() 方法很简单,只需要看到最后一句 delete this; 就明白了。
参考博文:http://blog.leafsoar.com/archives/2013/05-05.html
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • cocos2d-x学习笔记(19)--label 、label atlas
  • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
  • Cocos2d-x学习(一):HelloWorld
  • cocos2dx在xcode下开发,编译到android上(2)
  • cocos2d 设置屏幕默认方向
  • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
  • Cocos2d-x 2.0 之 Actions “三板斧” 之一
  • cocos2d-x学习笔记(18)--游戏打包(windows平台)
  • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1