Cocos2d-x HelloWorld初见
来源:互联网 发布:明事理 辨是非 知荣辱 编辑:程序博客网 时间:2024/05/19 21:59
1.从官方网站的下载页面 http://www.cocos2d-x.org/download 下载最新的Cocos2d-x(C++版) 源码。
2.Mac环境下安装Cocos2d-x,启动终端进入install-templates-xcode.sh所在的目录,然后输入“sudo ./install-templates-xcode.sh”命令开始执行安装命令,Xcode便有了Cocos2d-x的模版。
3.打开Xcode新建一个cocos2dx项目,可见如下界面:
4.运行这个项目在Iphone模拟器上,可以看到一个“Hello World”界面。
5.查看工程目录如下:
其中Resource是资源文件夹,主要存放游戏中需要的图片、音频和配置等资源文件。
ios文件夹中包含main函数和初始化界面控制器的文件,主要做了创建窗口、设置全屏、设置屏幕转向等方法,还包含cocos2dx的整个生命周期。
libs文件夹是cocos2dx引擎及其扩展的源代码。
Classes目录中放置我们最主要的程序。"AppDelegate.h"和"AppDelegate.cpp"文件是Cocos2d-x游戏的通用入口文件。
6.打开"AppDelegate.cpp", 在 bool applicationDidFinishLaunching() 这个方法中,默认的实现了游戏启动后的必要准备:
// 初始化游戏引擎控制器CCDirector,以便启动游戏引擎 CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); // 启用FPS显示 pDirector->setDisplayStats(true); // 设置绘制间隔 pDirector->setAnimationInterval(1.0 / 60); // 创建一个场景,它是自动释放的对象 CCScene *pScene = HelloWorld::scene(); // 运行 pDirector->runWithScene(pScene);
// on "init" you need to initialize your instancebool 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... // add a label shows "Hello World" // create and initialize a label CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34); // 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 - 20) ); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition( ccp(size.width/2, size.height/2) ); // add the sprite as a child to this layer this->addChild(pSprite, 0); return true;}void HelloWorld::menuCloseCallback(CCObject* pSender){ CCDirector::sharedDirector()->end();#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0);#endif}
0 0
- Cocos2d-x HelloWorld初见
- Cocos2d-x 剖析HelloWorld
- cocos2d-x HelloWorld基本原理
- cocos2d-x之helloworld
- Cocos2d-x 经典HelloWorld
- cocos2d-x HelloWorld 分析
- cocos2d-x Helloworld 详解
- cocos2d-x helloworld 分析
- Cocos2d-x之helloworld
- Cocos2d-x之helloworld
- Cocos2d-x之HelloWorld
- Cocos2d-x 之 HelloWorld
- 编译Cocos2d-x的HelloWorld
- [cocos2d-x] -- 新建HelloWorld工程
- [cocos2d-x] -- 新建HelloWorld工程 .
- cocos2d-x ——HelloWorld
- cocos2d-x3.x之helloWorld
- cocos2d-x安装以及HelloWorld
- android开机自动启动
- Jquery全屏图片自动切换插件,支持窗口变化图片大小等比例变化
- 将博客搬至CSDN
- 《计算机科学导论》读书笔记
- vSphere Client提示分析clients.xml文件出错解决办法
- Cocos2d-x HelloWorld初见
- 我爱他
- c++中fstream类对文本文件的操作
- 利用TSQL脚本将备份数据自动上传到ftp
- Zookeeper简介
- java反射机制详解 及 Method.invoke解释
- 深入浅出TCP/IP中的send和recv
- unix高级环境编程 例子 代码实现练习 第十二章:线程控制
- CI框架(三)config.php配置文件解读