cocos2d学习02——CCApplication类中的run方法分析

CCApplication类中的run方法分析

 1: int CCApplication::run()
 2: {
 3:     PVRFrameEnableControlWindow(false);    //windows相关的,不理会
 4:
 5:     // Main message loop: message消息loop循环
 6:     MSG msg;
 7:     LARGE_INTEGER nFreq;
 8:     LARGE_INTEGER nLast;
 9:     LARGE_INTEGER nNow;
 10:     //WinBase.h中声明的两个函数,不用理会
 11:     QueryPerformanceFrequency(&nFreq);
 12:     QueryPerformanceCounter(&nLast);
 13:
 14:     //初始化cocos2d应用实例
 15:     // Initialize instance and cocos2d.
 16:     if (!applicationDidFinishLaunching())
 17:     {
 18:         //applicationDidFinishLaunching()函数在AppDelegate中实现
 19:         return 0;
 20:     }
 21:     //下面都是和windows窗口显示相关的,暂时不理会
 22:     CCEGLView* pMainWnd = CCEGLView::sharedOpenGLView();
 23:     pMainWnd->centerWindow();
 24:     ShowWindow(pMainWnd->getHWnd(),SW_SHOW);
 25:     //死循环,程序
 26:     while (1)
 27:     {
 28:         if (! PeekMessage(&msg,NULL,PM_REMOVE))
 29:         {
 30:             // Get current time tick.获取当前时间标记
 31:             QueryPerformanceCounter(&nNow);
 32:             //获取到的时间是绘制下一个帧的时间,就绘制。否则继续while循环
 33:             // If it's the time to draw next frame,draw it,else sleep a while.
 34:             if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)
 35:             {
 36:                 nLast.QuadPart = nNow.QuadPart;
 37:                 CCDirector::sharedDirector()->mainLoop();
 38:             }
 39:             else
 40:             {
 41:                 Sleep(0);
 42:             }
 43:             continue;
 44:         }
 45:
 46:         if (WM_QUIT == msg.message)
 47:         {
 48:             // Quit message loop.
 49:             break;
 50:         }
 51:
 52:         // Deal with windows message.
 53:         if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd,m_hAccelTable,&msg))
 54:         {
 55:             TranslateMessage(&msg);
 56:             dispatchMessage(&msg);
 57:         }
 58:     }
 59:
 60:     return (int) msg.wParam;
 61: }

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...