解析cocos2d test项目(二)
2017-01-07 13:48
281 查看
我好厉害呀,都写到二了。啊,装疯卖傻一波,明明就几句话,还要换一章,mdzz。
废话有点多,我这个人。我们继续说AppDelegate 分为.h和.cpp两个文件。(我一直搞不懂,为啥要多个头文件,
定义声明写在一起感觉可能更有爱一点,应该也有我所不了解的细节吧)
我们这里先看AppDelegate.h
首先public的这几个我都还眼熟,我毕竟不是第一次看cocos2d,我还是打过那个HelloWorld的练习。
AppDelegate();
virtual ~AppDelegate();
首先是构造函数和析构函数,析构函数声明为虚函数由于:
在实现多态时,当用基类操作派生类,在析构时防止只析构基类而不析构派生类的状况发生。
virtual void initGLContextAttrs();//这是个什么玩意?去搜索了一下,说是设置OpenGL属性什么的,我记得cocos2d的一个优点就是隐藏了OpenGL什么的,说是我们不需要懂OpenGL就可以做游戏。反正我又不想做什么动画渲染啥的,应该不用了解,以后再说。
接下来这三个就很重要了
virtual bool applicationDidFinishLaunching();//这是程序启动过程中的第一个回调函数,我们在这里做一些初始化操作,我搜索关于该函数的调用
//我发现在int Application::run()中有这样代码,所以我们又多了一个疑问,Application是个啥玩意。
int Application::run()
{
\\前省略
if (!applicationDidFinishLaunching())
{
return 1;
}
\\后省略
}
virtual void applicationDidEnterBackground();//说明:当程序被推送到后台的时候调用。所以要设置后台继续运行,则在这个函数里面设置即可,搜索调用出现了
void GLViewImpl::onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
{
if (iconified == GL_TRUE)
{
Application::getInstance()->applicationDidEnterBackground();
}
else
{
Application::getInstance()->applicationWillEnterForeground();
}
}
My god ,问题越来越多了,这又是个啥,GLViewImpl应该和OpenGL有什么关系吧,同OpenGL一同暂时搁置吧,大概只要了解这是把程序推到后台就好了,暂时。
virtual void applicationWillEnterForeground();//说明:当程序从后台将要重新回到前台时候调用,这个刚好跟上面的那个方法相反。
搜索调用时同样出现了些坑爹的东西,还是GLViewImpl我就不贴出来了,看着闹心。
此外这三个函数全部在一个ApplicationProtocol里被声明为纯虚函数,我们应该可以猜想,AppDelegate的继承链上应该有这个类。
此外,这三个之外还有一个private:TestController* _testController;
关于这个应该是test项目特有的定义,我记得我在HelloWorld中没有看到过这个,应该不在API。
研究完AppDelegate.h总结一下:
一、我们知道的,应该背下来的:
这玩意继承了Application,我们暂时还不知道那是什么,虽然通过英文可以有一些大致的猜测
这玩意有构造函数和析构函数,AppDelegate();virtual ~AppDelegate();我们在main函数中调用了构造函数,但析构函数啥时候调用还不太清楚。
那三个最重要的函数(就是那几个名字差不多的函数)作用,applicationDidFinshLaunching() applicationDIdEnterBackground() applicationWillEnterForeground()
二、接下来要探索的:
1Application是个啥
2ApplicationProtocol是个啥
3TestController是个啥
4析构函数啥时候调用
三、暂时搁置:
1initGLContextAttrs()
2三个函数的具体调用GLViewImpl作用
额,接下来看AppDelegate.cpp文件,啊等等,我还没吃午饭,那待会儿再说。
废话有点多,我这个人。我们继续说AppDelegate 分为.h和.cpp两个文件。(我一直搞不懂,为啥要多个头文件,
定义声明写在一起感觉可能更有爱一点,应该也有我所不了解的细节吧)
我们这里先看AppDelegate.h
#ifndef _APP_DELEGATE_H_ #define _APP_DELEGATE_H_ #include "cocos2d.h" class TestController; /** @brief The cocos2d Application. Private inheritance here hides part of interface from Director. */ class AppDelegate : private cocos2d::Application { public: AppDelegate(); virtual ~AppDelegate(); virtual void initGLContextAttrs(); /** @brief Implement Director and cocos2d::Scene* init code here. @return true Initialize success, app continue. @return false Initialize failed, app terminate. */ virtual bool applicationDidFinishLaunching(); /** @brief Called when the application moves to the background @param the pointer of the application */ virtual void applicationDidEnterBackground(); /** @brief Called when the application reenters the foreground @param the pointer of the application */ virtual void applicationWillEnterForeground(); private: TestController* _testController; }; #endif // _APP_DELEGATE_H_
首先public的这几个我都还眼熟,我毕竟不是第一次看cocos2d,我还是打过那个HelloWorld的练习。
AppDelegate();
virtual ~AppDelegate();
首先是构造函数和析构函数,析构函数声明为虚函数由于:
在实现多态时,当用基类操作派生类,在析构时防止只析构基类而不析构派生类的状况发生。
virtual void initGLContextAttrs();//这是个什么玩意?去搜索了一下,说是设置OpenGL属性什么的,我记得cocos2d的一个优点就是隐藏了OpenGL什么的,说是我们不需要懂OpenGL就可以做游戏。反正我又不想做什么动画渲染啥的,应该不用了解,以后再说。
接下来这三个就很重要了
virtual bool applicationDidFinishLaunching();//这是程序启动过程中的第一个回调函数,我们在这里做一些初始化操作,我搜索关于该函数的调用
//我发现在int Application::run()中有这样代码,所以我们又多了一个疑问,Application是个啥玩意。
int Application::run()
{
\\前省略
if (!applicationDidFinishLaunching())
{
return 1;
}
\\后省略
}
virtual void applicationDidEnterBackground();//说明:当程序被推送到后台的时候调用。所以要设置后台继续运行,则在这个函数里面设置即可,搜索调用出现了
void GLViewImpl::onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
{
if (iconified == GL_TRUE)
{
Application::getInstance()->applicationDidEnterBackground();
}
else
{
Application::getInstance()->applicationWillEnterForeground();
}
}
My god ,问题越来越多了,这又是个啥,GLViewImpl应该和OpenGL有什么关系吧,同OpenGL一同暂时搁置吧,大概只要了解这是把程序推到后台就好了,暂时。
virtual void applicationWillEnterForeground();//说明:当程序从后台将要重新回到前台时候调用,这个刚好跟上面的那个方法相反。
搜索调用时同样出现了些坑爹的东西,还是GLViewImpl我就不贴出来了,看着闹心。
此外这三个函数全部在一个ApplicationProtocol里被声明为纯虚函数,我们应该可以猜想,AppDelegate的继承链上应该有这个类。
此外,这三个之外还有一个private:TestController* _testController;
关于这个应该是test项目特有的定义,我记得我在HelloWorld中没有看到过这个,应该不在API。
研究完AppDelegate.h总结一下:
一、我们知道的,应该背下来的:
这玩意继承了Application,我们暂时还不知道那是什么,虽然通过英文可以有一些大致的猜测
这玩意有构造函数和析构函数,AppDelegate();virtual ~AppDelegate();我们在main函数中调用了构造函数,但析构函数啥时候调用还不太清楚。
那三个最重要的函数(就是那几个名字差不多的函数)作用,applicationDidFinshLaunching() applicationDIdEnterBackground() applicationWillEnterForeground()
二、接下来要探索的:
1Application是个啥
2ApplicationProtocol是个啥
3TestController是个啥
4析构函数啥时候调用
三、暂时搁置:
1initGLContextAttrs()
2三个函数的具体调用GLViewImpl作用
class TestController; class AppDelegate : private cocos2d::Application\\Application是什么我们需要探究 { public: AppDelegate(); virtual ~AppDelegate(); \\构造函数和析构函数的具体细节我们需探索.cpp文件 virtual void initGLContextAttrs();//暂记为设置OpenGL属性,至于OpenGL是啥,暂时搁置 /** @brief Implement Director and cocos2d::Scene* init code here. @return true Initialize success, app continue. @return false Initialize failed, app terminate. */ virtual bool applicationDidFinishLaunching();//运行过程中第一个回调函数,用于初始化造作 /** @brief Called when the application moves to the background @param the pointer of the application */ virtual void applicationDidEnterBackground();//当程序被推到后台是调用该函数,从而实现一些细节 /** @brief Called when the application reenters the foreground @param the pointer of the application */ virtual void applicationWillEnterForeground();//同上,当程序从后台推到前台是调用 private: TestController* _testController;//需探究controller文件,是test项目自己定义的类,不属于cocos2d api }; #endif // _APP_DELEGATE_H_
额,接下来看AppDelegate.cpp文件,啊等等,我还没吃午饭,那待会儿再说。
相关文章推荐
- 解析cocos2d test项目(一)
- (4)Cocos2d-x的Helloworld项目工程架构解析
- cocos2d-x之TestCPP例子解析(1)-整体框架
- cocos2d笔记 (2)解析cocos2d项目整体框架和启动流程
- Cocos2d-TestCpp之项目结构分析
- Quick-Cocos2d-x初学者游戏教程(三) ---------------------------- 解析quick新建项目的代码文件
- cocos2d-x之TestCPP例子解析(2)-ActionsTest
- Cocos2d-x新手学习之TestCpp项目结构分析(第四篇)[版本:cocos2d-x-3.1.1]
- 解析cocos2d-lua项目中的Hello World
- 微信小程序全方位深度解析课程Dome-First项目test
- cocos2d-x 3.x中各种平台的创建项目命令,运行项目命令、运行testcpp命令
- Cocos2d-x基础:TestCpp之项目结构分析
- eclipse导入maven项目,把src/main, src/test直接解析成包名的错误
- cocos2d-x 3.x中各种平台的创建项目命令,运行项目命令、运行testcpp命令
- cocos2d-x-lua-加载官方test项目
- cocos2d-js解析官方js-test实例入口
- 解析cocos2d-lua项目中的Hello World
- cocos2d-x:参考案例源码解析之二:TestCpp万变不离其宗Main入口点
- cocos2d-x 3.x中各种平台的创建项目命令,运行项目命令、运行testcpp命令
- 解析Cocos2d项目整体框架和启动流程