《初学cocos2d-x》- 第一个项目(1)
来源:互联网 发布:安全教育平台软件 编辑:程序博客网 时间:2024/05/18 00:59
最近离职休息找工作,无聊,给自己找点事儿,研究一下cocos2d-x。
首先新建一个项目
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
bool HelloWorld::init(){ ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback) ); pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) ); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // create and initialize a label CCLabelTTF* pLabel = CCLabelTTF::create("达达's first world!", "Thonburi", 40); CCLabelTTF* labelm = CCLabelTTF::create("qq群:85935444", "Thonburi", 20); labelm->setColor(ccc3(255,0,255)); labelm->setPosition(ccp(250.0f,120.0f)); this->addChild(labelm); // ask director the window size CCSize size = CCDirector::sharedDirector()->getWinSize(); // position the label on the center of the screen pLabel->setPosition( ccp(size.width / 2, size.height - 60) ); // add the label as a child to this layer this->addChild(pLabel, 1); CCSprite* pSprite = CCSprite::create("dada.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(100.0f, 100.0f)); // add the sprite as a child to this layer this->addChild(pSprite, 0); return true;}
完成!
代码下载:http://download.csdn.net/detail/dadagm/4751176
- 《初学cocos2d-x》- 第一个项目(1)
- cocos2d-x 第一个项目
- (3)Cocos2d-x新建第一个项目之HelloWorld
- 创建cocos2d-x第一个android项目
- cocos2d-x创建第一个项目
- 创建第一个cocos2d-x项目HelloWorld
- 2、创建第一个cocos2d-x项目
- Cocos2d-x学习(二) 在Cocos2d-x2.2.6搭建你第一个项目
- 第一个COCOS2d项目
- quick-cocos2d-x教程1:在window上创建第一个项目目录,并制作helloworld
- 第一个cocos2d-x程序
- 创建第一个cocos2d-x
- cocos2d-x游戏开发(二)之创建第一个项目
- 初触cocos2d-x,win32平台搭建以及创建第一个cocos2d-x项目遇到问题总结
- 初触cocos2d-x,win32平台搭建以及创建第一个cocos2d-x项目遇到问题总结
- cocos2d-js第一个项目(cocos2d-html5)
- cocos2d-x总结:第一个场景(scene) [2.0.1]
- 【Cocos2d-x】开发基础-第一个Cocos2d-x游戏
- Linux多线程编程
- VBScript 小笔记2
- jquery控制网页局部打印
- apache shiro
- Android的Activity屏幕切换动画左右滑动切换
- 《初学cocos2d-x》- 第一个项目(1)
- 多线程同步
- myeclipse中常遇到的一个问题
- 软考 程序员
- Castle AOP 系列(三):实现一个简单的调用指令路由(有源码)未整理
- android ViewFlow
- C++编程技巧推荐
- SQLPLUS的LOGIN脚本
- MFC多线程消息传递