AppDelegate

AppDelegate 继承自Application, 负责控制游戏的生命周期

class  AppDelegate : private cocos2d::Application
{
public:
    AppDelegate();
    virtual ~AppDelegate();

    /**<span style="white-space:pre">	@brief 启动结束以后,实现导演类和场景的初始化</span>
      * @return true   成功,APP继续
<pre name="code" class="cpp">      * @return false   失败,APP停止
*/ virtual bool applicationDidFinishLaunching(); /** @return false   失败,APP停止
 
     */
    virtual void applicationDidEnterBackground();

    /** @brief  APP从后台回归以后
      */
    virtual void applicationWillEnterForeground();

  在main函数中被调用

int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR    lpCmdLine,
                       int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // create the application instance
    AppDelegate app;
    return Application::getInstance()->run();
}

AppDelegate  继承于Application.main调用了Application的run()函数;

在看到Application的构造函数

Application::Application()
: _instance(nullptr)
, _accelTable(nullptr)
{
    _instance    = GetModuleHandle(nullptr);
    _animationInterval.QuadPart = 0;
    CC_ASSERT(! sm_pSharedApplication);
    sm_pSharedApplication = this;
}

所以main函数中AppDelegate app;这句,主要是为了实例化Application的单利对象,然后调用run(),run里面又会调用applicationDidFinishLaunching,和mainLoop().

  // Initialize instance and cocos2d.
    if (!applicationDidFinishLaunching())
    {
        return 0;
    }

    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();

    // Retain glview to avoid glview being released in the while loop
    glview->retain();

    while(!glview->windowShouldClose())
    {
        QueryPerformanceCounter(&nNow);
        if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)
        {
            nLast.QuadPart = nNow.QuadPart;
            
            director->mainLoop();
            glview->pollEvents();
        }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值