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

前端之家收集整理的这篇文章主要介绍了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: }
原文链接:https://www.f2er.com/cocos2dx/346113.html

猜你在找的Cocos2d-x相关文章