cocos studio工程分析

如下图

1.jpg


文件分析:

Classes:存放跨平台的C++代码

cocosstudio:放置项目中使用的所有资源

proj.Android用于开发Android上的游戏

proj.ios_mac:用于开发苹果手机上的游戏

proj.win32:用于开发Windows上的游戏

Resource:用于保存资源

cocos-project.json:项目配置文件

myProject.ccs:Cocos Studio项目的启动文件,双击该文件可以开启您的Cocos studio项目

myProject.cfg:项目配置文件,用于管理您的项目配置信息

myProject.udf:项目配置文件

使用Visual Studio 2012打开项目后的项目工程文件结构

2.jpg

代码分析:

main.cpp中的代码(本人已经注释)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "main.h"  
#include "AppDelegate.h"  
#include "cocos2d.h"  
   
//Cocos2d-X的命名空间  
USING_NS_CC;  
   
//链接静态链接库  
#if _MSC_VER > 1700  
#pragma comment(lib,"libcocos2d_2013.lib")  
#pragma comment(lib,"libbox2d_2013.lib")  
#pragma comment(lib,"libSpine_2013.lib")  
#else  
#pragma comment(lib,"libcocos2d_2012.lib")  
#pragma comment(lib,"libbox2d_2012.lib")  
#pragma comment(lib,"libSpine_2012.lib")  
#endif  
   
//Cocos2d-X的main函数  
int  APIENTRY _tWinMain( HINSTANCE  hInstance,  
                        HINSTANCE  hPrevInstance,  
                        LPTSTR     lpCmdLine,  
                        int        nCmdShow)  
{  
     UNREFERENCED_PARAMETER(hPrevInstance);  
     UNREFERENCED_PARAMETER(lpCmdLine);  
   
     //创建程序实例  
     AppDelegate app;  
   
     //执行app的run方法  
     return  Application::getInstance()->run();  
}

AppDelegate.h中的代码(本人已经注释)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef  _APP_DELEGATE_H_  
#define  _APP_DELEGATE_H_  
   
#include "cocos2d.h"  
   
//AppDelegate继承自Application  
class   AppDelegate :  private  cocos2d::Application  
{  
public :  
     //构造函数  
     AppDelegate();  
   
     //析构函数  
     virtual  ~AppDelegate();  
   
     //初始化OpenGL属性  
     virtual  void  initGLContextAttrs();  
   
     //当程序启动后调用的函数  
     virtual  bool  applicationDidFinishLaunching();  
   
     //当程序进入后台后调用的函数  
     virtual  void  applicationDidEnterBackground();  
   
    //当程序恢复到前台后调用的函数  
     virtual  void  applicationWillEnterForeground();  
};  
   
#endif

AppDelegate.cpp中的代码(本人已经注释)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "AppDelegate.h"  
#include "HelloWorldScene.h"  
   
//Cocos2d-X的命名空间  
USING_NS_CC;  
   
//构造函数  
AppDelegate::AppDelegate() {  
   
}  
   
//析构函数  
AppDelegate::~AppDelegate()   
{  
}  
   
   
//设置OpenGL属性  
void  AppDelegate::initGLContextAttrs()  
{  
     //设置OpenGL上下文属性,现在只能设置六个属性:  
     //红,绿,蓝,阿尔法,深度,模板  
     GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};  
     GLView::setGLContextAttrs(glContextAttrs);  
}  
   
   
//程序启动完成后会进入的函数    
bool  AppDelegate::applicationDidFinishLaunching()   
{  
     //初始化导演  
     auto director = Director::getInstance();  
   
     //获得OpenGL视图  
     auto glview = director->getOpenGLView();  
   
     if (!glview)   
     {  
         //设置程序名和窗口的尺寸  
         glview = GLViewImpl::createWithRect( "myProject" , Rect(0, 0, 960, 640));  
       
         //设置OpenGL视图  
         director->setOpenGLView(glview);  
     }  
   
     //设置分辨率  
     director->getOpenGLView()->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);  
   
     //设置是否显示调试信息  
     director->setDisplayStats( true );  
   
     //设置帧率  
     director->setAnimationInterval(1.0 / 60);  
   
     //设置文件的搜索路径  
     FileUtils::getInstance()->addSearchPath( "res" );  
   
     //调用场景  
     auto scene = HelloWorld::createScene();  
   
     //执行场景  
     director->runWithScene(scene);  
   
     return  true ;  
}  
   
   
//当别人打电话来的时候调用的函数,程序进入后台  
void  AppDelegate::applicationDidEnterBackground()   
{  
     //停止播放动画  
     Director::getInstance()->stopAnimation();  
   
     //如果程序中有背景音乐,停止播放背景音乐   
     //SimpleAudioEngine::getInstance()->pauseBackgroundMusic();  
}  
   
//当通话结束后,程序进入前台  
void  AppDelegate::applicationWillEnterForeground()   
{  
     //播放动画  
     Director::getInstance()->startAnimation();  
   
     //当程序中有背景音乐的时候继续播放背景音乐  
     //SimpleAudioEngine::getInstance()->resumeBackgroundMusic();  
}

HelloWorldScene.h中的代码(本人已经注释)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef __HELLOWORLD_SCENE_H__  
#define __HELLOWORLD_SCENE_H__  
   
#include "cocos2d.h"  
   
//HelloWorld继承自Layer  
class  HelloWorld :  public  cocos2d::Layer  
{  
public :  
     //创建场景  
     static  cocos2d::Scene* createScene();  
   
     //初始化场景  
     virtual  bool  init();  
   
     // 实施静态的create方法  
     CREATE_FUNC(HelloWorld);  
};  
   
#endif // __HELLOWORLD_SCENE_H__

HelloWorldScene.cpp中的代码(本人已经注释)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "HelloWorldScene.h"  
#include "cocostudio/CocoStudio.h"  
#include "ui/CocosGUI.h"  
   
USING_NS_CC;  
   
//使用动画需要引入的命名空间  
using  namespace  cocostudio::timeline;  
   
//场景创建函数  
Scene* HelloWorld::createScene()  
{  
     //创建场景  
     auto scene = Scene::create();  
       
     //创建层  
     auto layer = HelloWorld::create();  
   
     //将层添加到场景中  
     scene->addChild(layer);  
   
     //返回场景  
     return  scene;  
}  
   
//场景初始化函数  
bool  HelloWorld::init()  
{  
     //初始化父类的层  
     if (!Layer::init())  
     {  
         return  false ;  
     }  
       
     //加载Coco studio的资费  
     auto rootNode = CSLoader::createNode( "MainScene.csb" );  
     addChild(rootNode);  
   
     return  true ;  
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值