成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

解析Cocos2d項目整體框架和啟動流程

移動開發 iOS 游戲開發
本文介紹的是解析Cocos2d項目整體框架和啟動流程,主要介紹了要處理的各種系統事件!

Cocos2d項目整體框架和啟動流程是本文要介紹的內容,在這里我們新建一個名為“Test2d”的項目,在xcode中的Group&Files中看到的文件結構如下所示:

解析Cocos2d項目整體框架和啟動流程

cocos2d Sources:存放的是cocos2d源代碼

Classes:存放本應用程序源代碼

Other Sources:   程序的入口main函數

Resources:存放本項目的圖片、圖標、聲音文件等等

Frameworks:框架,順一下啟動流程

從main函數進入:

  1. #import <UIKit/UIKit.h>    
  2.      
  3.  int main(int argc, char *argv[]) {    
  4.      NSAutoreleasePool *pool = [NSAutoreleasePool new];    
  5.     int retVal = UIApplicationMain(argc, argv, nil, @"Test2dAppDelegate");    
  6.      [pool release];    
  7.      return retVal;    
  8.  }  

第5行標識將程序的控制權傳遞給了應用代理程序對象Test2dAppDelegate、Test2dAppDelegate

  1. Test2dAppDelegate<SPAN style="FONT-SIZE: 14px; LINE-HEIGHT: 21px; FONT-FAMILY: verdana, 'courier new'; WHITE-SPACE: normal">頭文件如下</SPAN>   
  2.  #import <UIKit/UIKit.h>    
  3.       
  4.  @interface Test2dAppDelegate : NSObject <UIApplicationDelegate> {    
  5.      UIWindow *window;    
  6.  }    
  7.  @property (nonatomic, retain) UIWindow *window;    
  8. @end  

第三行能看出Test2dAppDelegate實現了系統定義的應用程序接口 UIApplicationDelegate

當前應用程序需要處理的各種系統事件:

放棄控制權:applicationWillResignActive 

獲得控制權:applicationDidBecomeActive 

內存報警:applicationDidReceiveMemoryWarning 

程序退出提示:applicationWillTerminate 

系統時間變化:applicationSignificantTimeChange

  1. //放棄控制權    
  2. (void)applicationWillResignActive:(UIApplication *)application {    
  3.     [[CCDirector sharedDirector] pause];    
  4.     
  5.      
  6. //獲得控制權    
  7. void)applicationDidBecomeActive:(UIApplication *)application {    
  8.    [[CCDirector sharedDirector] resume];    
  9. }    
  10.    
  11. //內存報警    
  12. (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {    
  13.     [[CCDirector sharedDirector] purgeCachedData];    
  14.  
  15.     
  16. //    
  17. (void) applicationDidEnterBackground:(UIApplication*)application {    
  18.    [[CCDirector sharedDirector] stopAnimation];    
  19. }    
  20.     //    
  21. void) applicationWillEnterForeground:(UIApplication*)application {    
  22.    [[CCDirector sharedDirector] startAnimation];    
  23. }       
  24. //程序退出提示    
  25. (void)applicationWillTerminate:(UIApplication *)application {    
  26.     [[CCDirector sharedDirector] end];    
  27.     
  28.     
  29. //系統時間變化    
  30.  (void)applicationSignificantTimeChange:(UIApplication *)application {    
  31.     [[CCDirector sharedDirector] setNextDeltaTimeZero:YES];    
  32. }  

在完成刜始處理之后,通過凼數 applicationDidFinishLaunching 將程序的控制權傳遞給 Cocos2D-iPhone 類庫,Cocos2D-iPhone 接下來開始準備啟勱 游戲主畫面的準備:

1.獲得主窗口對象(句柄)由成員 window 保存。

2.將 Cocos2D-iPhone 的“導演”對象與之綁定。

3. 設置“導演”對象的基本屬性。

 

  1. (void) applicationDidFinishLaunching:(UIApplication*)application    
  2.  {    
  3.     // CC_DIRECTOR_INIT()    
  4.     //    
  5.     // 1. Initializes an EAGLView with 0-bit depth format, and RGB565 render buffer    
  6.     // 2. EAGLView multiple touches: disabled    
  7.      // 3. creates a UIWindow, and assign it to the "window" var (it must already be declared)    
  8.      // 4. Parents EAGLView to the newly created window    
  9.     // 5. Creates Display Link Director    
  10.      // 5a. If it fails, it will use an NSTimer director    
  11.     // 6. It will try to run at 60 FPS    
  12.      // 7. Display FPS: NO    
  13.      // 8. Device orientation: Portrait    
  14.      // 9. Connects the director to the EAGLView    
  15.      //    
  16.      CC_DIRECTOR_INIT();    
  17.              // Obtain the shared director in order to...    
  18.     CCDirector *director = [CCDirector sharedDirector];    
  19.                /***********設置“導演”對象的基本屬性***************/   
  20.       //設置主窗口方向(垂直還是水平)  
  21.       // Sets landscape mode  
  22.        [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; 
  1. //是否顯示FPS(每秒顯示的幀數)    
  2.  // Turn on display FPS    
  3.  [director setDisplayFPS:YES];    
  4.    //設定Director對象與當前窗口的關系,便于Director操作主窗口    
  5.  // Turn on multiple touches    
  6.  EAGLView *view = [director openGLView];    
  7.  [view setMultipleTouchEnabled:YES];            
  8.  //設定主窗口顯示圖像的調色盤位寬<BR>   // Default texture format for PNG/BMP/TIFF/JPEG/GIF images    
  9.  // It can be RGBA8888, RGBA4444, RGB***1, RGB565    
  10.  // You can change anytime.    
  11.  [CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];               
  12.      //導演對象啟動并運行場景    
  13.  [[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];    

Cocos2d-iPhone的主畫面對象 – HellowWorldScene 場景

場景對象 HellowWorldScence 獲得控制權后通過初始化凼數 init,直接在主畫面中創建一個帶有“Hello world”內容的Lable。將該標簽的位置為屏幕的中央。

  1. (id) init    
  2.  {    
  3.     // always call "super" init    
  4.     // Apple recommends to re-assign "self" with the "super" return value    
  5.      if( (self=[super init] )) {                
  6.          // create and initialize a Label    
  7.         CCLabel* label = [CCLabel labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];    
  8.          // ask director the the window size    
  9.          CGSize size = [[CCDirector sharedDirector] winSize];    
  10.           
  11.         // position the label on the center of the screen    
  12.          label.position =  ccp( size.width /2 , size.height/2 );                
  13.          // add the label as a child to this Layer    
  14.          [self addChild: label];    
  15.      }    
  16.      return self;    
  17.  }  

Cocos2D-iPhone 的基本導入框架就是確保 main 凼數調用正確的 應用程序代理對象。

在應用代理對象的 applicationDidFinishLaunching 凼數中:

創建“層“對象

將層傳遞給新創建的“場景“

通過“導演“對象運行新建的”場景“對象。

小結:解析Cocos2d項目整體框架和啟動流程的內容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 博客園
相關推薦

2011-08-08 17:17:55

Cocos2D 坐標 OpenglES

2012-06-01 10:27:44

Cocos2d觸摸分發原理

2011-08-11 17:52:01

Cocos2d游戲對象

2011-08-08 15:40:47

Cocos2d

2011-07-27 13:57:36

iPhone 游戲 Cocos2d

2011-07-27 10:13:23

Cocos2D iPhone

2011-08-11 18:00:18

Cocos2d動作Action

2011-07-29 18:02:06

2011-07-20 14:04:46

Cocos2d iPhone 游戲

2011-07-27 13:44:08

2011-08-02 15:37:48

Cocos2D UIAccelero

2011-08-09 16:25:16

Cocos2d視圖坐標

2012-02-19 20:10:23

Cocos2d-x fCocos2dWindows Pho

2011-08-08 11:26:39

Cocos2d 游戲 Class類

2011-07-27 14:48:21

iPhone Cocos2D 坐標

2011-07-08 16:09:54

Cocoa Cocos2d 動作

2011-08-02 15:47:28

Cocos2D Animation

2011-08-04 17:01:16

iPhone游戲開發 Cocos2d

2011-08-11 14:22:47

iPhone游戲Cocos2D

2011-07-08 16:27:52

Cocoa Cocos2d 動作
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久国产精品一区二区三区 | 九九热免费在线观看 | 中文字幕在线视频精品 | 欧美激情精品久久久久久 | 激情欧美一区二区三区中文字幕 | 久久亚洲国产 | 日韩福利片 | 亚洲三级av | 欧美一级久久精品 | 日日日操 | 毛片的网址 | 精品国产一区二区国模嫣然 | 精品国产乱码久久久久久牛牛 | 国产成人久久精品一区二区三区 | 国产视频一区二区在线观看 | 日日操操操| 久久久观看 | 久久综合久久自在自线精品自 | 欧美福利一区 | 国产高清毛片 | 中文字幕1区2区3区 亚洲国产成人精品女人久久久 | 欧美激情a∨在线视频播放 成人免费共享视频 | 狠狠亚洲 | 久久av一区二区三区 | 91免费入口| 亚洲一区国产 | 国产高潮好爽受不了了夜夜做 | 九九热国产精品视频 | 欧美专区在线 | 亚洲国产精品视频一区 | 日本不卡一区 | 久久国产精品-国产精品 | 夜夜爽99久久国产综合精品女不卡 | 国产一区高清 | 91精品一区二区三区久久久久 | 欧美一区视频在线 | 国产精品大全 | 成人在线免费观看视频 | 日本一本在线 | 一区亚洲| 亚洲精品一区久久久久久 |