Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cocos2d-x 3.6 程序流程大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
    @H_713_2@main.cpp
#include "main.h"
#include "AppDelegate.h" //应用委托
#include "cocos2d.h" //主要的头文件

USING_NS_Cc;//名字空间

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();//应用单列运行
}
  1. run 方法:
int application::run()
{
    PVRFrameEnableControlWindow(false);

    // Main message loop:
    LARGE_IntegeR nLast;
    LARGE_IntegeR nNow;

    QueryPerfoRMANceCounter(&nLast);

    initGLContextAttrs();

    // Initialize instance and cocos2d.
    if (!applicationDidFinishLaunching())// 初始化,资源适配,屏幕适配,运行第一个场景等代码 
    {
        return 1;
    }

    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 - (nNow.QuadPart % _animationInterval.QuadPart);

            director->@H_444_7@mainLoop();//主循环逻辑代码!!!
            glview->pollEvents();
        }
        else
        {
            Sleep(1);
        }
    }
    //程序退出(清理资源)
    // Director should still do a cleanup if the window was closed manually.
    if (glview->isOpenGLReady())
    {
        director->end();
        director->@H_444_7@mainLoop();
        director = nullptr;
    }
    glview->release();
    return 0;
}
  1. applicationDidFinishLaunching 方法
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::geTinstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);//显示FPS,设为false则关闭显示

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

    register_all_packages();

    // create a scene. it's an autorelease object
    auto scene = HelloWorld::createScene(); //场景创建

    // run
    director->runWithScene(scenE);

    return true;
}
    @H_713_2@mainLoop 方法
void DisplayLinkDirector::mainLoop()
{
    if (_purgeDirectorInNextLoop)
    {
        _purgeDirectorInNextLoop = false;
        purgeDirector();
    }
    else if (_restartDirectorInNextLoop)
    {
        _restartDirectorInNextLoop = false;
        restartDirector();
    }
    else if (! _invalid)
    {
        drawScene();// 屏幕绘制及一些相应的逻辑处理

        // release the objects
        PoolManager::geTinstance()->getCurrentPool()->clear();
    }
}

大佬总结

以上是大佬教程为你收集整理的cocos2d-x 3.6 程序流程全部内容,希望文章能够帮你解决cocos2d-x 3.6 程序流程所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。