Cocos2d-x学习笔记(二)AppDelegate类详解
由源代码,可得到如下的类继承关系:

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类详解的更多相关文章
- CDN学习笔记二(技术详解)
一本好的入门书是带你进入陌生领域的明灯,<CDN技术详解>绝对是带你进入CDN行业的那盏最亮的明灯.因此,虽然只是纯粹的重点抄录,我也要把<CDN技术详解>的精华放上网.公诸同 ...
- C#学习笔记二: C#类型详解
前言 这次分享的主要内容有五个, 分别是值类型和引用类型, 装箱与拆箱,常量与变量,运算符重载,static字段和static构造函数. 后期的分享会针对于C#2.0 3.0 4.0 等新特性进行. ...
- IP2——IP地址和子网划分学习笔记之《子网掩码详解》
2018-05-04 16:21:21 在学习掌握了前面的<进制计数><IP地址详解>这两部分知识后,要学习子网划分,首先就要必须知道子网掩码,只有掌握了子网掩码这部分内容 ...
- [读书笔记]C#学习笔记三: C#类型详解..
前言 这次分享的主要内容有五个, 分别是值类型和引用类型, 装箱与拆箱,常量与变量,运算符重载,static字段和static构造函数. 后期的分享会针对于C#2.0 3.0 4.0 等新特性进行. ...
- jQuery学习笔记之Ajax用法详解
这篇文章主要介绍了jQuery学习笔记之Ajax用法,结合实例形式较为详细的分析总结了jQuery中ajax的相关使用技巧,包括ajax请求.载入.处理.传递等,需要的朋友可以参考下 本文实例讲述了j ...
- [Spring学习笔记 5 ] Spring AOP 详解1
知识点回顾:一.IOC容器---DI依赖注入:setter注入(属性注入)/构造子注入/字段注入(注解 )/接口注入 out Spring IOC容器的使用: A.完全使用XML文件来配置容器所要管理 ...
- 【Java学习笔记之三十三】详解Java中try,catch,finally的用法及分析
这一篇我们将会介绍java中try,catch,finally的用法 以下先给出try,catch用法: try { //需要被检测的异常代码 } catch(Exception e) { //异常处 ...
- MyBatis学习笔记2--配置环境详解
1.MyBatis-config.xml详解 一个完整的配置文件如下所示 <configuration> <!-- <properties resource="jdb ...
- CSS学习笔记(9)--详解CSS中:nth-child的用法
详解CSS中:nth-child的用法 前端的哥们想必都接触过css中一个神奇的玩意,可以轻松选取你想要的标签并给与修改添加样式,是不是很给力,它就是“:nth-child”. 下面我将用几个典型的实 ...
- ubuntu学习笔记-tar 解压缩命令详解(转)
tar 解压缩命令详解 -c: 建立压缩档案 -x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能 ...
随机推荐
- [py]py常用模块小结
- python md5校验: https://blog.csdn.net/linda1000/article/details/17581035 import hashlib hashlib.md5( ...
- 关于Flag的定义
最近在维护项目的代码,发现了由于Flag不一致导致的很多问题,现在对这一问题总结. 1,flag分为两种,可以组合的和不可以组合的.可以组合的flag适合用每一位表示一个含义.不适合组合的flag适合 ...
- ps中的栅格化--引出--矢量图
矢量图使用直线和曲线来描述图形,这些图形的元素是一些点.线.矩形.多边形.圆和弧线等等,它们都是通过数学公式计算获得的.例如一幅花的矢量图形实际上是由线段形成外框轮廓,由外框的颜色以及外框所封闭的颜色 ...
- Http请求中Content-Type和Accept讲解以及在Spring MVC中的应用
在Http请求中,我们每天都在使用Content-type来指定不同格式的请求信息,但是却很少有人去全面了解content-type中允许的值有多少,这里将讲解Content-Type的可用值,以及在 ...
- GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3
Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3 ...
- mysql主从延迟(摘自http://www.linuxidc.com/Linux/2012-02/53995.htm)
http://www.linuxidc.com/Linux/2012-02/53995.htm
- AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 6. Mathematical Concepts and Methods
uva 106 这题说的是 说计算 x^2 + y^2 = z^2 xyz 互质 然后计算个数和 在 N内 不在 勾股数之内的数的个数 然后去找需要的 维基百科上 看到 另 n*m*2 =b ...
- mustache多次渲染和多个赋值
mustache多次渲染和多个赋值, html页面的script标签中的代码,设置多个键: <!-- 项目列表 --> <script type="text/x-templ ...
- python webdriver 登陆163邮箱给QQ邮箱发送一个邮件,显示等待
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- 2017-2018-2 20165207 实验四《Android开发基础》实验报告
2017-2018-2 20165207 实验四<Android开发基础>实验报告 检查点1 安装测试Android Studio: 安装Android Studio 安装过程比较艰难,一 ...