• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
linux_ios
博客园    首页    新随笔    联系   管理    订阅  订阅

第一个cocos2d-x 项目

熟悉4个常用的类

  • CCSprite  精灵       游戏种角色    可以移动,缩放,旋转,动画 等。
  • CCLayer   层          游戏基本都是层组合层的 
  • CCScene   场景      
  1. 主界面
  2. 关卡选择界面
  3. Loading界面
  4. 游戏界面
  5. 。。。。。。
  • CCDirector   导演   主要负责不同的场景之间的切换   也可以控制整个游戏流程

AppDelegatede 3个生命周期函数

 

 1 //项目启动后入口函数
 2 
 3  
 4 
 5 bool AppDelegate::applicationDidFinishLaunching()
 6 
 7 {
 8 
 9 //这两行是初始化导演  : 注意  一个游戏中只有一个导演
10 
11     // initialize director
12 
13     CCDirector *pDirector = CCDirector::sharedDirector();
14 
15     pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
16 
17  
18 
19 //这一行是设置显示状态信息   包括:1 当前对象个数  2 每一帧的使用时间 3 当前游戏的整体的帧数 
20 
21     // turn on display FPS
22 
23     pDirector->setDisplayStats(true);
24 
25  //设置游戏的帧率为每秒 60 帧
26 
27     // set FPS. the default value is 1.0/60 if you don't call this
28 
29     pDirector->setAnimationInterval(1.0 / 60);
30 
31  //创建一个场景 scene 
32 
33     // create a scene. it's an autorelease object
34 
35     CCScene *pScene = HelloWorld::scene();
36 
37  //然后导演在游戏屏幕中进行展现
38 
39     // run
40 
41     pDirector->runWithScene(pScene);
42 
43  
44 
45     return true;
46 
47 }
48 
49  //当程序切换到后台时候发生的。
50 
51 // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
52 
53 void AppDelegate::applicationDidEnterBackground()
54 
55 {
56 
57 // 下面第一行是对整个游戏设置暂停
58 
59     CCDirector::sharedDirector()->pause();
60 
61  
62 
63     // if you use SimpleAudioEngine, it must be paused
64 
65 //设置暂停音乐  当程序切入后台 对音乐所作的处理
66 
67     // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
68 
69 }
70 
71 // 当程序被用户切换到当前运行时候响应
72 
73 // this function will be called when the app is active again
74 
75 void AppDelegate::applicationWillEnterForeground()
76 
77 {
78 
79 //设置游戏继续
80 
81     CCDirector::sharedDirector()->resume();
82 
83     
84 
85     // if you use SimpleAudioEngine, it must resume here
86 
87  //音乐继续播放
88 
89     // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
90 
91 }

 

 

 

以上可以运行项目了   

下面是 默认的项目截图

 

 

 

posted @ 2013-03-27 19:09  linux_ios  阅读(318)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3