cocos2d-x 3.6 程序流程

cocos2d-x 3.6 程序流程,第1张

概述main.cpp #include "main.h"#include "AppDelegate.h" //应用委托#include "cocos2d.h" //主要的头文件USING_NS_CC;//名字空间int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance 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();//应用单列运行}
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->mainLoop();//主循环逻辑代码!!!            glvIEw->pollEvents();        }        else        {            Sleep(1);        }    }    //程序退出(清理资源)    // Director should still do a cleanup if the window was closed manually.    if (glvIEw->isOpenglready())    {        director->end();        director->mainLoop();        director = nullptr;    }    glvIEw->release();    return 0;}
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;}
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 程序流程所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1063895.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存