COCOS2D-X学习之路(二)——分析APPDELEGATE和HELLOWORLDSCENE文件

 这里我们来看一下cocos自动给我们生成的工程里有些什么东西,并且分析一下这些代码的用途,来为我们以后编写cocos程序铺下基础。

这里我建议看我这份随笔的看官先看看cocos官网的快速入门手册,不然可能会比较迷糊(因为待会要分析一些代码,如果以前没见过的话会比较昏)。

既然是自己的demo嘛,当然要给自己打个广告啦(那个居中的图标显然是cocos的logo)

这个界面里面有一些我们可以直接看出来的东西:

这里所有的元素都是我根据以往用过的引擎猜测的,实际上我们还是要看一下代码。不过我们目前知道大概有这么些东西了,待会可以针对着看一下。

然后我们可以看看这些资源在哪里,我通过XCODE可以直接看到: 

这里logo是HelloWorld.png,右下角的开关机图标是CloseNormal.png,而那个CloseSelected.png是按下按钮的图片。


 

分析AppDelegate

好的,到我们的分析阶段了。AppDelegate分为头文件和实现文件。我们当然是先看头文件啦。这个文件在Classes文件夹下。

复制代码
 1 #ifndef  _APP_DELEGATE_H_  2 #define  _APP_DELEGATE_H_ 3  4 #include "cocos2d.h" 5  6 /**  7 @brief    The cocos2d Application.  8  9 Private inheritance here hides part of interface from Director. 10 */11 class  AppDelegate : private cocos2d::Application 12 { 13 public: 14     AppDelegate();  //构造函数 15     virtual ~AppDelegate();  //析构函数 16 17     virtual void initGLContextAttrs();  //这个暂时不知道是干什么的 18 19     /** 20     @brief    Implement Director and Scene init code here. 21     @return true    Initialize success, app continue. 22     @return false   Initialize failed, app terminate. 23     */24     virtual bool applicationDidFinishLaunching(); 25 26     /** 27     @brief  Called when the application moves to the background 28     @param  the pointer of the application 29     */30     virtual void applicationDidEnterBackground(); 31 32     /** 33     @brief  Called when the application reenters the foreground 34     @param  the pointer of the application 35     */36     virtual void applicationWillEnterForeground(); 37 }; 38 39 #endif // _APP_DELEGATE_H_
复制代码

关键字:
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信