cocos2d-x 入门——hello world 解析
来源:互联网 发布:java打印乘法表 编辑:程序博客网 时间:2024/05/21 10:13
接下来我们来看,AppDelegate的代码。
先看申明
class AppDelegate : private cocos2d::CCApplication{public: AppDelegate(); virtual ~AppDelegate(); /** @brief Implement CCDirector and CCScene init code here. @return true Initialize success, app continue. @return false Initialize failed, app terminate. */ virtual bool applicationDidFinishLaunching(); /** @brief The function be called when the application enter background @param the pointer of the application */ virtual void applicationDidEnterBackground(); /** @brief The function be called when the application enter foreground @param the pointer of the application */ virtual void applicationWillEnterForeground();};
里面都有注释,主要看函数applicationDidFinishLaunching()
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector* pDirector = CCDirector::sharedDirector(); CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView);CCSize frameSize = pEGLView->getFrameSize(); // Set the design resolution#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll);#else pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);#endif vector<string> searchPath; // In this demo, we select resource according to the frame's height. // If the resource size is different from design resolution size, you need to set contentScaleFactor. // We use the ratio of resource's height to the height of design resolution, // this can make sure that the resource's height could fit for the height of design resolution. // if the frame's height is larger than the height of medium resource size, select large resource.if (frameSize.height > mediumResource.size.height){ searchPath.push_back(largeResource.directory); pDirector->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));} // if the frame's height is larger than the height of small resource size, select medium resource. else if (frameSize.height > smallResource.size.height) { searchPath.push_back(mediumResource.directory); pDirector->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); } // if the frame's height is smaller than the height of medium resource size, select small resource.else { searchPath.push_back(smallResource.directory); pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); } // set searching path CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *pScene = HelloWorld::scene(); // run pDirector->runWithScene(pScene); return true;}
pDirector是导演类。
重点看这句
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
pDirector->runWithScene(pScene);
这样他就运行起一个helloworld的场景。
接下来的逻辑就是hello world的内容了
还是看申明:
class HelloWorld : public cocos2d::CCLayer{public: // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual bool init(); // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d::CCScene* scene(); // a selector callback void menuCloseCallback(CCObject* pSender); // implement the "static node()" method manually CREATE_FUNC(HelloWorld);};
我们一个一个函数来分析:
CREATE_FUNC(HelloWorld);
这个宏用来申明 HelloWorld的creat函数。
to be continue
0 0
- cocos2d-x 入门——hello world 解析
- Android入门—— Hello, world 解析
- 【入门精选】cocos2d-x从Hello World开始
- Vert.x入门:Hello World!
- Cocos2d-x--"Hello World"深入分析
- cocos2d-x教程1 hello world
- cocos2d-x之浅析Hello World
- cocos2d-x-3.3rc2-001-hello-world
- 【Cocos2d-x 游戏开发】 1 --- Hello World
- cocos2d-x 的安装以及hello world
- cocos2d-x hello.lua解析
- 解析cocos2d-lua项目中的Hello World
- 入门Qt——hello, world
- Android入门—— Hello, world
- 入门Qt——hello, world
- OSGI入门——Hello World
- Ubuntu入门——hello world
- 入门Qt——hello, world
- linux .so 文件中函数名称和程序中的函数名称相同
- android应用程序中启动另一个应用程序
- 收藏:bat常用
- Handler本质简析与使用实例
- 音量图标
- cocos2d-x 入门——hello world 解析
- 谈谈如何做好移动端的产品
- Linux任务调度(一)—at
- OpenCV图像分割cv::grabCut()函数
- Vi编辑器基本使用方法
- 敏捷团队经验之谈,你的团队也能成为特总部队
- IOS7 IOS5 IOS6 内容覆盖住的问题 解决方法
- zookeeper master动态选举实现设计
- SVN服务器搭建和使用(二)