paoku流程

///D:\cocos2d-x-2.2.6\cocos2d-x-2.2.6\projects\paoku\proj.win32\main.cpp

///_tWinMain 

AppDelegate app;//本身类里构造里什么也没做,但父类构造里赋值了句柄和程序指针
    CCEGLView* eglView = CCEGLView::sharedOpenGLView();
    eglView->setViewName("HelloCpp");//设置名字
    eglView->setFrameSize(480, 320);
    return CCApplication::sharedApplication()->run();


////猜测以CCApplication::sharedApplication()->run()为主



/////////////

CCApplication::CCApplication()
: m_hInstance(NULL)
, m_hAccelTable(NULL)
{
    m_hInstance    = GetModuleHandle(NULL);//模块句柄
    m_nAnimationInterval.QuadPart = 0;
    CC_ASSERT(! sm_pSharedApplication);
    sm_pSharedApplication = this;//设置单件对象指针指向当前类对象实例 
}




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())//这里开始调用AppDelegate::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;
}

////////

//程序启动后调用的函数,在这里创建设备与场景
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());


    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
    // pDirector->enableRetinaDisplay(true);


    // turn on display FPS
    pDirector->setDisplayStats(true);


    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);


    // create a scene. it's an autorelease object
    CCScene *pScene = GameMenu::scene();//创建菜单场景 先运行菜单场景


    // run
    pDirector->runWithScene(pScene);//运行菜单场景


    return true;
}

void CCDirector::runWithScene(CCScene *pScene)
{
    CCAssert(pScene != NULL, "This command can only be used to start the CCDirector. There is already a scene present.");
    CCAssert(m_pRunningScene == NULL, "m_pRunningScene should be null");


    pushScene(pScene);
    startAnimation();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值