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

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. [py]编码-强力理解版

    py编码骨灰级总结 思路: python执行py文件步骤--py2/3定义变量时unicode差异 1,py2 py3执行py文件的步骤 2,py2 定义变量x='mao' 1.x='mao', # ...

  2. 搭建基于HTTP协议内网yum仓库

    目录 1. 前言 2. 把rpm包下载到本地 3. 配置nginx对外提供服务 4. 配置本地repo文件 5. 生成repodata信息 6. 检查及使用 7. 对管理机器上的仓库进行更新 参考资料 ...

  3. 软件包管理:源码包管理-源码包与RPM包的区别

    RPM会安装在默认位置,源码包会安装在指定位置. 绝大多数ROM包遵循此规范.写软件包是就固定好了. 主要影响体现在对服务的管理方法,服务的管理分三种:启动,重启动,停止. 启动时使用绝对路径来启动. ...

  4. PIMPL(二)

    文档下载 上一篇文档,PIMPL(一) 1 如何使用PIMPL 有多种方式实现PIMPL,这里按照<Effective C++>中介绍的方式. 1.1 基本步骤 假设原有Person如下: ...

  5. MYSQL主从不同步延迟原理分析及解决方案(摘自http://www.jb51.net/article/41545.htm)

    1. MySQL数据库主从同步延迟原理.要说延时原理,得从mysql的数据库主从复制原理说起,mysql的主从复制都是单线程的操作,主 库对所有DDL和DML产生binlog,binlog是顺序写,所 ...

  6. BP神经网络的Java实现(转)

    http://fantasticinblur.iteye.com/blog/1465497 课程作业要求实现一个BPNN.这次尝试使用Java实现了一个.现共享之.版权属于大家.关于BPNN的原理,就 ...

  7. hihocoder博弈游戏·Nim游戏·三

    在这一次游戏中Alice和Bob决定在原来的Nim游戏上增加一条规则:每一次行动时,不仅可以选择一堆取走任意数量的石子(至少取1颗,至多取出这一堆剩下的所有石子),还可以选择将一堆石子分成两堆石子,但 ...

  8. pandas练习(一)------ 了解数据

    探索Chipotle快餐数据 (相关数据见github) 步骤1 导入pandas库 import pandas as pd 步骤2 导入数据集 path1 = "./data/chipot ...

  9. linux常用命令:ping 命令

    Linux系统的ping 命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地 址192.168.1.1试试 ...

  10. UVA12995 Farey Sequence

    UVA12995 Farey Sequence 欧拉函数 同仪仗队那题几乎相同,本质都是求欧拉函数的和 #include<cstdio> #define N 1000000 ],i,j,t ...