cocos2d-x 3.6 程序流程
2015-07-14 17:55
387 查看
main.cpp
run 方法:
applicationDidFinishLaunching 方法
mainLoop 方法
#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-x3.0下一个 Lua与C++打电话给对方
- cocos2d学习之旅(零)
- vs2012 编译cocos2d-x项目报error MSB3073
- cocos2dx中实现拖尾的效果
- 【Cocos2d-js官方文档】 五、Cocos2d-JS v3.0的新Action API
- Cocos2d-js中Chipmunk引擎
- Cocos2d-x action动作整理集合
- Cocos2d-x中Sprite的自动拉伸
- Cocos2D-x 入门(2) win7(64)+VS2013+cocos2d-x 3.6环境配置
- Cocos2d html5 逐帧动画
- Cocos2d-x 22种特效
- 记录:牛牛游戏开发笔记
- Cocos2d-JS 特效
- Cocos2d-JS加速度计与加速度事件
- 我的第一个Cocos2D-x 程序
- cocos2dx 单点触摸的简单使用
- Cocos2D-x 入门(1)
- 分析Cocos2d-x横版ACT手游源 1、登录
- Quick-Cocos2d-x 3.3绑定自定义类至Lua(四)使用绑定C++至Lua的自定义类
- Quick-Cocos2d-x 3.3绑定自定义类至Lua(三)动手绑定自定义类至Lua