编辑: 向日葵8AS | 2016-08-20 |
4 在cocos2d-x应用启动以后会创建一个opengl窗口用来实现图形绘制和事件处理 draw()???? 该方法绘制每一个node update() 该方法处理每一帧的逻辑变化 ccTouchesBegan() 处理用户的交互事件 当cocos2d-x 应用启动以后会执行 CCApplication::sharedApplication()->
run();
我们看下具体代码: int CCApplication::run(PVRFrameEnableControlWindow(false);
??? // Main message loop:???? MSG msg;
???? LARGE_INTEGER nFreq;
???? LARGE_INTEGER nLast;
???? LARGE_INTEGER nNow;
??? QueryPerformanceFrequency(&
nFreq);
???? QueryPerformanceCounter(&
nLast);
??? // Initialize instance and cocos2d.???? if (!applicationDidFinishLaunching(return 0;
???? } ??? CCEGLView* pMainWnd = CCEGLView::sharedOpenGLView();
???? pMainWnd->
centerWindow();
???? ShowWindow(pMainWnd->
getHWnd(), SW_SHOW);
??? while (1)if (! PeekMessage(&
msg, NULL, 0, 0, PM_REMOVE)Get current time tick.QueryPerformanceCounter(&
nNow);
If it'
s the time to draw next frame, draw it, else sleep a while.if (nNow.QuadPart - nLast.QuadPart >
m_nAnimationInterval.QuadPart)nLast.QuadPart = nNow.QuadPart;
CCDirector::sharedDirector()->
mainLoop(else?Sleep(0)continue;
??????? if (WM_QUIT == msg.message)Quit message loop.break;
Deal with windows message.if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &
msg)TranslateMessage(&
msg)DispatchMessage(&
msg) ??? return (int) msg.wParam;
?} CCDirector::sharedDirector()->
mainLoop();
?我们看到CCDirect实现了应用的主循环,我们看下循环中做的工作是什么 void CCDisplayLinkDirector::mainLoop(void)?{???? if (m_bPurgeDirecotorInNextLoop)m_bPurgeDirecotorInNextLoop = false;
purgeDirecto........