xcode5 cocos2d-x3.0 二 第一个项目(你好,亮哥)

来源:互联网 发布:java 跨行字符串 编辑:程序博客网 时间:2024/06/05 00:42

首先新建一个项目



next




next  然后保存到一个你希望的位置。


OK项目建完了,开始看一下结构。




Group&Files 


1.Resources


Default.png 加载IOS显示的图片
Icon.png 应用图标
fps_images.png cocos2d显示帧,不润徐删除或者修改
Info.plist 应用程序相关的配置信息


2.main.m


大多数时候不需要对main.m进行修改,main和AppDelegate之间的操作都是由iphone sdk自行处理的。
可以理解成,main函数创建了NSAutoreleasePool,调用UIApplicationMain来启动应用程序,AppDelegate用来实现UIApplicationDelegate协议类。


3.prefix.pch
快速预编工具,永远不会变化或者很少发生变化的头晚间才能被添加到当前缀头文件中。


4.AppDelegate类
AppDelegate类通过特定时间从设备接收消息来追踪应用程序的状态变化。
应用程序收到的第一个消息是applicationDidFinishLaunching方法,cocoa2d的初始化代码都是写到这个方法里面。其中

FPS显示开关
pDirector->setDisplayStats(true);


设置刷新率 1/60 ,ios设备最好的情况是每秒60帧,这个跟游戏逻辑复杂性有直接关系,当然可以设置低一点。
游戏过于复杂FPS值不停波动,这样会影响游戏体验,如果真是这样,那么就可以思考一下代码的质量了
pDirector->setAnimationInterval(1.0 / 60);


当应用程序是不活跃时或来电时,都会调用
applicationDidEnterBackground()方法


当应用程序再次活跃的时候,调用
applicationWillEnterForeground()方法


5.写一个helloWorld

[cpp] view plaincopyprint?
  1. bool HelloWorld::init()  
  2. {  
  3.     //////////////////////////////  
  4.     // 1. super init first  
  5.     if ( !CCLayer::init() )  
  6.     {  
  7.         return false;  
  8.     }  
  9.   
  10.     /////////////////////////////  
  11.     // 2. add a menu item with "X" image, which is clicked to quit the program  
  12.     //    you may modify it.  
  13.   
  14.     // add a "close" icon to exit the progress. it's an autorelease object  
  15.     CCMenuItemImage *pCloseItem = CCMenuItemImage::create(  
  16.                                         "CloseNormal.png",  
  17.                                         "CloseSelected.png",  
  18.                                         this,  
  19.                                         menu_selector(HelloWorld::menuCloseCallback) );  
  20.     pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );  
  21.   
  22.     // create menu, it's an autorelease object  
  23.     CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);  
  24.     pMenu->setPosition( CCPointZero );  
  25.     this->addChild(pMenu, 1);  
  26.   
  27.     /////////////////////////////  
  28.     // 3. add your codes below...  
  29.   
  30.     // create and initialize a label  
  31.     CCLabelTTF* pLabel = CCLabelTTF::create("你好:亮哥""Thonburi", 60);  
  32.   
  33.     CCLabelTTF* labelm  =   CCLabelTTF::create("qq:11674183""Thonburi", 34);  
  34.   
  35.     labelm->setColor(ccc3(186,30,46));  
  36.       
  37.     labelm->setPosition(ccp(450.0f,400.0f));  
  38.       
  39.     this->addChild(labelm);  
  40.       
  41.     // ask director the window size  
  42.     CCSize size = CCDirector::sharedDirector()->getWinSize();  
  43.   
  44.     // position the label on the center of the screen  
  45.     pLabel->setPosition( ccp(size.width / 2, size.height - 80) );  
  46.   
  47.     // add the label as a child to this layer  
  48.     this->addChild(pLabel, 1);  
  49.   
  50.     CCSprite* pSprite = CCSprite::create("dada.png");  
  51.   
  52.     // position the sprite on the center of the screen  
  53.   
  54.     pSprite->setPosition(ccp(100.0f, 300.0f));  
  55.       
  56.     // add the sprite as a child to this layer  
  57.     this->addChild(pSprite, 0);  
  58.       
  59.     return true;  
  60. }  

0 0
原创粉丝点击