由源代码,可得到如下的类继承关系:

1. 在方法applicationDidFinishLaunching中,首先会调用CCDirector* pDirector = CCDirector::sharedDirector()来初始化导演类,导演类是一个单例,由下方法中可知,创建的是一个CCDisplayLinkDirector类对象。它是CCDirector的直接继承子类。

CCDirector* CCDirector::sharedDirector(void)
{
if (!s_SharedDirector)
{
s_SharedDirector = new CCDisplayLinkDirector();
s_SharedDirector->init();
} return s_SharedDirector;
}

关于DisplayLinkDirector:

DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display.

2. CCEGLView用于UI的显示,在win32平台是一个窗体,用于点击、按键和触摸等事件的处理。在Create()方法中,会创建窗体和初始化GL底层的东西。

调用CCEGLView* pEGLView = CCEGLView::sharedOpenGLView()完成操作。单例。一般看到sharedxxx创建的对象,都是单例。

CCEGLView* CCEGLView::sharedOpenGLView()
{ if (s_pEglView == NULL)
{
s_pEglView = new CCEGLView();
if(!s_pEglView->Create())
{
delete s_pEglView;
s_pEglView = NULL;
}
} return s_pEglView;
}

CCEGLView的作用:

This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. The view content is basically an EAGL surface you render your OpenGL scene into. Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.

3. pDirector->setOpenGLView(pEGLView)设置OpenGL视图,将在2中创建的View对象传给Director,并完成做一些相关操作:

void CCDirector::setOpenGLView(CCEGLView *pobOpenGLView)
{
CCAssert(pobOpenGLView, "opengl view should not be null"); if (m_pobOpenGLView != pobOpenGLView)
{
// Configuration. Gather GPU info
CCConfiguration *conf = CCConfiguration::sharedConfiguration();
conf->gatherGPUInfo();
conf->dumpInfo(); // EAGLView is not a CCObject
if(m_pobOpenGLView)
delete m_pobOpenGLView; // [openGLView_ release]
m_pobOpenGLView = pobOpenGLView; // set size
m_obWinSizeInPoints = m_pobOpenGLView->getDesignResolutionSize(); createStatsLabel(); if (m_pobOpenGLView)
{
setGLDefaultValues();
} CHECK_GL_ERROR_DEBUG(); m_pobOpenGLView->setTouchDelegate(m_pTouchDispatcher);
m_pTouchDispatcher->setDispatchEvents(true);
}
}

4. pDirector->setDisplayStats(true)打开显示开关。

/** Display the FPS on the bottom-left corner */
inline void setDisplayStats(bool bDisplayStats) { m_bDisplayStats = bDisplayStats; }

5. pDirector->setAnimationInterval(1.0 / 60)设置帧频。

void CCApplication::setAnimationInterval(double interval)
{
LARGE_INTEGER nFreq;
QueryPerformanceFrequency(&nFreq);
m_nAnimationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);
}

6. CCScene *pScene = HelloWorld::scene()创建一个场景,这是一个自动回收的对象。

具体代码将在HelloWorld类中介绍。

7. pDirector->runWithScene(pScene)运行创建的Scene,游戏真正开始于此。

// scene management
void CCDirector::runWithScene(CCScene *pScene)
{
CCAssert(pScene != NULL, "This command can only be used to start the CCDirector. There is already a scene present.");
CCAssert(m_pRunningScene == NULL, "m_pRunningScene should be null"); pushScene(pScene);
startAnimation();
}


1. applicationDidEnterBackground方法将会在app进入到后台时调用。

CCDirector::sharedDirector()->stopAnimation()会停止动画。这里还可以停止背景音乐等。

void CCDisplayLinkDirector::stopAnimation(void)
{
m_bInvalid = true;
}


1. applicationWillEnterForeground方法将会在app进入前台时调用。

CCDirector::sharedDirector()->startAnimation()开启动画。这里还可以开启背景音乐。

// should we implement 4 types of director ??
// I think DisplayLinkDirector is enough
// so we now only support DisplayLinkDirector
void CCDisplayLinkDirector::startAnimation(void)
{
if (CCTime::gettimeofdayCocos2d(m_pLastUpdate, NULL) != )
{
CCLOG("cocos2d: DisplayLinkDirector: Error on gettimeofday");
} m_bInvalid = false;
#ifndef EMSCRIPTEN
CCApplication::sharedApplication()->setAnimationInterval(m_dAnimationInterval);
#endif // EMSCRIPTEN
}

Cocos2d-x学习笔记(二)AppDelegate类详解的更多相关文章

  1. CDN学习笔记二(技术详解)

    一本好的入门书是带你进入陌生领域的明灯,<CDN技术详解>绝对是带你进入CDN行业的那盏最亮的明灯.因此,虽然只是纯粹的重点抄录,我也要把<CDN技术详解>的精华放上网.公诸同 ...

  2. C#学习笔记二: C#类型详解

    前言 这次分享的主要内容有五个, 分别是值类型和引用类型, 装箱与拆箱,常量与变量,运算符重载,static字段和static构造函数. 后期的分享会针对于C#2.0 3.0 4.0 等新特性进行. ...

  3. IP2——IP地址和子网划分学习笔记之《子网掩码详解》

    2018-05-04 16:21:21   在学习掌握了前面的<进制计数><IP地址详解>这两部分知识后,要学习子网划分,首先就要必须知道子网掩码,只有掌握了子网掩码这部分内容 ...

  4. [读书笔记]C#学习笔记三: C#类型详解..

    前言 这次分享的主要内容有五个, 分别是值类型和引用类型, 装箱与拆箱,常量与变量,运算符重载,static字段和static构造函数. 后期的分享会针对于C#2.0 3.0 4.0 等新特性进行. ...

  5. jQuery学习笔记之Ajax用法详解

    这篇文章主要介绍了jQuery学习笔记之Ajax用法,结合实例形式较为详细的分析总结了jQuery中ajax的相关使用技巧,包括ajax请求.载入.处理.传递等,需要的朋友可以参考下 本文实例讲述了j ...

  6. [Spring学习笔记 5 ] Spring AOP 详解1

    知识点回顾:一.IOC容器---DI依赖注入:setter注入(属性注入)/构造子注入/字段注入(注解 )/接口注入 out Spring IOC容器的使用: A.完全使用XML文件来配置容器所要管理 ...

  7. 【Java学习笔记之三十三】详解Java中try,catch,finally的用法及分析

    这一篇我们将会介绍java中try,catch,finally的用法 以下先给出try,catch用法: try { //需要被检测的异常代码 } catch(Exception e) { //异常处 ...

  8. MyBatis学习笔记2--配置环境详解

    1.MyBatis-config.xml详解 一个完整的配置文件如下所示 <configuration> <!-- <properties resource="jdb ...

  9. CSS学习笔记(9)--详解CSS中:nth-child的用法

    详解CSS中:nth-child的用法 前端的哥们想必都接触过css中一个神奇的玩意,可以轻松选取你想要的标签并给与修改添加样式,是不是很给力,它就是“:nth-child”. 下面我将用几个典型的实 ...

  10. ubuntu学习笔记-tar 解压缩命令详解(转)

    tar 解压缩命令详解 -c: 建立压缩档案 -x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能 ...

随机推荐

  1. Scala系统学习(二):Scala开发环境安装配置

    Scala可以安装在任何基于UNIX/Linux或基于Windows的系统上.在您的机器上开始安装Scala之前,必须在计算机上安装Java 1.8或更高版本. 下面请按照以下步骤安装Scala. 步 ...

  2. [javascript]编码&i字符串格式化&nput历史记录&清空模态框

    js中编码问题 https://www.haorooms.com/post/js_escape_encodeURIComponent 我在前端js添加时候创建dom时候,有汉字,发现是乱码就研究了下 ...

  3. 使用 sendKeys(keysToSend) 批量上传文件

    未经允许,禁止转载!!! 在selenium里面处理文件上传的时候可以使用sendKeys(keysToSend) 上传文件 例如: element.sendKeys(“C:\\test\\uploa ...

  4. os模块的使用

    python编程时,经常和文件.目录打交道,这是就离不了os模块.os模块包含普遍的操作系统功能,与具体的平台无关.以下列举常用的命令 1. os.name()——判断现在正在实用的平台,Window ...

  5. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) D. Something with XOR Queries

    地址:http://codeforces.com/contest/872/problem/D 题目: D. Something with XOR Queries time limit per test ...

  6. 缓存(图像 IO 14.2)

    缓存 如果有很多张图片要显示,最好不要提前把所有都加载进来,而是应该当移出屏幕之后立刻销毁.通过选择性的缓存,你就可以避免来回滚动时图片重复性的加载了. 缓存其实很简单:就是存储昂贵计算后的结果(或者 ...

  7. CAMediaTiming`协议(9.1 图层时间)

    #CAMediaTiming`协议 CAMediaTiming协议定义了在一段动画内用来控制逝去时间的属性的集合,CALayer和CAAnimation都实现了这个协议,所以时间可以被任意基于一个图层 ...

  8. C/C++之static函数与普通函数

    全局变量(外部变量)的说明之前再冠以static 就构成了静态的全局变量.全局变量本身就是静态存储方式, 静态全局变量当然也是静态存储方式.这两者在存储方式上并无不同.这两者的区别虽在于非静态全局变量 ...

  9. ELK学习笔记之Logstash详解

    0x00 Logstash概述 官方介绍:Logstash is an open source data collection engine with real-time pipelining cap ...

  10. Python入门之实现简单的购物车功能

    Talk is cheap,Let's do this! product_list = [ ['Iphone7 Plus', 6500], ['Iphone8 ', 8200], ['MacBook ...