cocos2dx 中 scene(), create(), init() 调用关系
来源:互联网 发布:windows输入法简繁体 编辑:程序博客网 时间:2024/05/24 01:43
最近在学cocos2d,刚上手时对示例程序的函数调用关系不是很清楚。昨晚刚刚搞清楚,记录下。
1. 首先来看main函数:
[cpp] view plaincopyprint? AppDelegate app; // 创建一个AppDelegate对象 ... return CCApplication::sharedApplication()->run(); // 运行 app 对象
2. 再看 AppDelegate 类:
[cpp] view plaincopyprint? virtual bool applicationDidFinishLaunching(); // CCApplication::sharedApplication()->run(); 之后首先执行此函数 // Implement CCDirector and CCScene init code here. bool AppDelegate::applicationDidFinishLaunching() { ... // create a scene. it's an autorelease object CCScene *pScene = HelloWorld::scene(); pDirector->runWithScene(pScene); return true; }
调用了层类(Layer)HelloWorld 的scene() 方法,并且通过 CCDirector 的一个实例来执行。
3. 最后看 HelloWorld 的 scene() 方法
[cpp] view plaincopyprint? CCScene* HelloWorld::scene() { // 'scene' is an autorelease object CCScene *scene = CCScene::create(); // 'layer' is an autorelease object HelloWorld *layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; }
这个时候,定位create() 方法,指向 CREATE_FUNC(HelloWorld);
[cpp] view plaincopyprint? /** * define a create function for a specific type, such as CCLayer * @__TYPE__ class type to add create(), such as CCLayer */ #define CREATE_FUNC(__TYPE__) \ static __TYPE__* create() \ { \ __TYPE__ *pRet = new __TYPE__(); \ if (pRet && pRet->init()) \ { \ pRet->autorelease(); \ return pRet; \ } \ else \ { \ delete pRet; \ pRet = NULL; \ return NULL; \ } \ }
4. 总结
调用顺序为 main() -> AppDelegate ->HelloWorld::scene() -> CREATE_FUNC() -> init()
来源:http://blog.csdn.net/ironyoung/article/details/39546009?utm_source=tuicool
0 0
- cocos2dx 中 scene(), create(), init() 调用关系
- cocos2dx 中 scene(), create(), init() 调用关系
- cocos2d 中 scene(), create(), init() 调用关系
- cocos2d 中 scene(), create(), init() 调用关系
- cocos2d 中 scene(), create(), init() 调用关系
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用顺序
- linux 中 init,inittab, init.d, rcX.d 系统启动之间的调用关系关系
- linux 中 init,inittab, init.d, rcX.d 系统启动之间的调用关系关系
- COCOS2DX-3.3调用COCOSTUDIO1.6中的SCENE和UI
- create Scene using script
- cocos2dx scene的理解
- Chapter4:栈的应用-将中缀表达式转换为后缀表达式
- java Future 接口介绍
- ARP原理
- RCP程序打包导出时乱码问题String literal is not properly closed by a double-quote
- json、xml解析
- cocos2dx 中 scene(), create(), init() 调用关系
- Chapter4:栈的应用-后缀表达式的计算
- 关于win7系统远程调试Hadoop时遇到的问题
- ubuntu账户密码正确但是登录不进去系统
- linux下生成.so文件和.a文件
- java---网络爬虫讲解
- MYSQL插入新字段
- Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a
- ENET(四)enet_protocol_send_acknowledgements