简介

CCDirector负责创建和处理主窗口,和管理场景的的执行。同时负责:

  • 初始化OpenGL ES的context
  • 设置OpenGL像素格式(默认是RGB565)
  • 设置OpenGL缓冲深度(默认是0-bit)
  • 设置投影模式(默认是3D)

CCDirector一般作为单件使用,标准用法是:[[CCDirector sharedDirector] methodName]。IOS下[CCDirector sharedDirector]返回的对象是CCDirectorDisplayLink。

CCDirector继承自UIViewController。CDirector是真个引擎的核心,它控制整个运行过程。一般初始化代码如下:

// Main Windowwindow_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];// Directordirector_ = (CCDirectorIOS*)[CCDirector sharedDirector];[director_ setDisplayStats:NO];[director_ setAnimationInterval:1.0/60];// GL ViewCCGLView *__glView = [CCGLView viewWithFrame:[window_ bounds]pixelFormat:kEAGLColorFormatRGB565depthFormat:0 /* GL_DEPTH_COMPONENT24_OES */preserveBackbuffer:NOsharegroup:nilmultiSampling:NOnumberOfSamples:0];[director_ setView:__glView];[director_ setDelegate:self];director_.wantsFullScreenLayout = YES;// Retina Display ?[director_ enableRetinaDisplay:useRetinaDisplay_];// Navigation ControllernavController_ = [[UINavigationController alloc] initWithRootViewController:director_];navController_.navigationBarHidden = YES;// AddSubView doesn't work on iOS6[window_ addSubview:navController_.view];
//     [window_ setRootViewController:navController_];[window_ makeKeyAndVisible];// create the main sceneCCScene *scene = [CCScene node];....// and run it![director_ pushScene: scene];

初始化流程:

1. director_ = (CCDirectorIOS*)[CCDirector sharedDirector];

[CCDirector sharedDirector]返回的对象是CCDirectorDisplayLink,创建CCScheduler(调度器)、CActionManager(动作管理器)、CCTouchDispatcher(触摸事件处理器),并把创建的动作管理器加入调度器,然后调度器就在时间片离调用CActionManager相关方法。(相关文件:CCDirector.m, CCDirectorIOS.m)

2. [director_ setAnimationInterval:1.0/60];  设置FPS。

3. 初始化GLView,为渲染准备一个视图。

3.   [director_ setView:__glView];

[director_ setDelegate:self];

Director是继承于UIViewController,设置视图和代理者。

4.   CCScene *scene = [CCScene node];

创建主场景。

5   [director_ pushScene: scene];

把主场景推入场景堆栈,并执行。

任务

  • Memory Helper:使用purgeCacheData方法,可以自动清除所有cocos2d缓存的数据
  • Scene OpenGL Helper:可以设置OpenGL的Alpha混合和深度检测(setAlphaBlending、setDethTest)
  • Director Integration with a UIKit view:
  • Director Scene Landscape:场景布局
  • Director Scene Management:管理场景(runWithscene, pushScene, popScene, replaceScene, end, pause, resume, stopAnimation,startAnimation,drawScene)

属性

  • runningThread:cocos2d线程
  • runningScene:当前正在运行的场景,cocos2d一次只能运行一个场景
  • animationInterval:FPS
  • displayStats:控制是否显示一些统计信息
  • isPaused:控制Director是否暂停
  • isAnimating:控制Director是否运行
  • projection:设置OpenGL的投影
  • totalFrames:从Director开始运行,执行的帧数
  • secondsPerFrame:每一帧用时
  • deltegate:实现CDirectorDelegate协议的代理对象
  • scheduler:调度器
  • actionManager:动作管理器
  • touchDispatcher:用户触摸操作的处理器

查看更多相关代码:test/DirectorTest.m

2013/01/24  14:44 于上海

转载于:https://www.cnblogs.com/mywolrd/archive/2013/02/01/2889316.html

cocos2d-iphone源码分析(2):Director相关推荐

  1. android源码分析

    01_Android系统概述 02_Android系统的开发综述 03_Android的Linux内核与驱动程序 04_Android的底层库和程序 05_Android的JAVA虚拟机和JAVA环境 ...

  2. 【Mybatis源码】源码分析

    [Mybatis源码]源码分析 (一)Mybatis重要组件 [1]四大核心组件 (1)SqlSessionFactoryBuilder (2)SqlSessionFactory (3)SqlSess ...

  3. Android shortcut的使用及源码分析

    Android shortcut的使用及源码分析 最近遇到了一个切换国家码后部分应用的shortcut未更新的问题,就学习了shortcut的相关知识,在这里分享一下我了解的知识,希望能对大家有帮助. ...

  4. SDL2源码分析之OpenGL ES在windows上的渲染过程

    SDL2源码分析之OpenGL ES在windows上的渲染过程 更新于2018年11月4日. 更新于2018年11月21日. ffmpeg + SDL2实现的简易播放器 ffmpeg和SDL非常强大 ...

  5. thinkphp6 框架源码分析

    一.入口概述 public/index.php // 执行HTTP应用并响应 $http = (new App())->setEnvName('local')->http;$respons ...

  6. Android上百实例源码分析以及开源分析集合打包

    感谢网友banketree的收集,压缩包的内容如下: 1.360新版特性界面源代码 实现了360新版特性界面的效果,主要涉及到Qt的一些事件处理与自定义控件.但源码好像是c++. 2.aidl跨进程调 ...

  7. Android应用Activity、Dialog、PopWindow、Toast窗口添加机制及源码分析

    1  背景 之所以写这一篇博客的原因是因为之前有写过一篇<Android应用setContentView与LayoutInflater加载解析机制源码分析>, 然后有人在文章下面评论和微博 ...

  8. ceph 代码分析 读_Ceph源码分析

    Ceph源码分析 作者:常涛 编著 出版日期:2016年10月 文件大小:2.34M 支持设备: ¥40.00在线试读 适用客户端: 言商书局 iPad/iPhone客户端:下载 Android客户端 ...

  9. 移动端开发基本知识之touch.js,FastClick.js源码分析

    问题1:300ms延迟问题指的是? 不管在移动端还是PC端,我们都需要处理用户点击,这个最常用的事件.但在touch端click事件响应速度会比较慢,在较老的手机设备上会更为明显(300ms的延迟). ...

  10. Java设计模式——工厂模式讲解以及在JDK中源码分析

    需求:便于手机种类的扩展 手机的种类很多(比如HuaWeiPhone.XiaoMiPhone等) 手机的制作有prepare,production, assemble, box 完成手机店订购功能. ...

最新文章

  1. 引用计数(Reference Counting)和代理(Proxy)的应用
  2. LeetCode 12 Integer to Roman (整数转罗马数字)
  3. C# AppDomain
  4. VS2010 用WebBrowser控件 无响应
  5. 关系数据库和nosql
  6. JS中的HTML片段
  7. Algs4-1.4.18数组的局部最小元素
  8. 简约易收录的导航网站源码
  9. C++标准库vector及迭代器
  10. Oracle中listener does not currently know of SID given in connect descriptor
  11. java h5 交互 传数组, JS数组/对象的值为什么变了?你需要深入理解对象的值传递...
  12. 十三种寂寞 你有过吗?『最无奈的是第13种』
  13. java am pm_【am.pm正确时间书写格式】作文写作问答 - 归教作文网
  14. 最少的脚本实现在NSH脚本作业中加入动态参数
  15. 2022年HELIUM3将引领链游开启gaming2.0时代
  16. java实现表情符号过滤
  17. Nagios nsca插件进程突然死掉
  18. RNN及变体LSTM、GRU(在NILM中的应用)
  19. Mac用Pycharm安装mediapipe报错ERROR: Could not find a version that satisfies the requirement mediapipe
  20. 机器学习中的特征选择——决策树模型预测泰坦尼克号乘客获救实例

热门文章

  1. mysql逻辑备份之mysqldump
  2. Switchover and Failover说明
  3. Spring Boot 传参方式
  4. java 杀掉 linux下进程和进程的子孙进程
  5. 【我拼搏的2016】-苦逼运维如何变身为SRE成长经历
  6. 为什么基于内容的读取缓存 (CBRC) 对于 Horizon View 和 VSAN 如此重要?
  7. mysql-创建函数,存储过程以及视图
  8. 定位低效SQL与不同的Extra类型(转载)
  9. 如何避免jps中一大堆spark-submit+Spark交互模式启动速度+正确的退出spark-shell/pyspark/SparkR/hbase的习惯
  10. ubuntu18.10安装linuxqq2.0