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:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能 ...
随机推荐
- js实现轮播图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- JS中“==”和“===”的原理和区别
1.为什么讨论这个问题? - 有个说法,尽量不用==,而使用===,是这样吗? 2.分析问题,原理是什么? 下面说说ECMAScript 5 language specification里的说明: 1 ...
- windows8.1的启动目录的路径
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\ 或者使用斜杠表示,就像这样: C:/ProgramData/Microsof ...
- 更换mysql数据库的datadir目录
更换过程如下: 1.新建指定的datadir目录,这里举例如:E:/mysql_datadir/data. 2.关闭mysql57服务器. 3.将原来的datadir目录下面的所有文件拷贝到E:/my ...
- mongodb mongotemplate聚合
1.group by并且计算总数 @Test public void insertTest() { //测试数据 //insertTestData(); Aggregation agg = Aggre ...
- RocketMQ 集群搭建--双Master方案
安装环境 jdk1.7 alibaba-rocketmq-3.2.6.tar.gz VM虚拟机redhat6.5-x64:192.168.1.201 192.168.1.202 Xshell4 部署 ...
- python webdriver 从无到有搭建数据驱动自动化测试框架的步骤和总结
一步一步搭建数据驱动测试框架的过程和总结 跟吴老学了搭建自动化数据驱动的框架后,我在自己练习的时候,尝试从简单的程序进行一点一点的扩展和优化,到实现这个数据驱动的框架. 先说一下搭建自动化测试框架的目 ...
- python webdriver 登陆163邮箱给QQ邮箱发送一个邮件,显示等待
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- javashop组件开发指南
javashop组件开发指南 1. 概念解释 组件:可以理解为是插件,功能点的一个集合. 插件:是指具体的某个功能. 插件桩:是负责调用插件. 事件:是要决定什么时候执行插件 一个组件是由多 ...
- 怎么查看CI,codeigniter的版本信息?想看某个项目中使用的CI具体是哪个版本,怎么查看?
怎么查看CI的版本信息?想看某个项目中使用的CI具体是哪个版本,怎么查看?system\core\codeigniter.php中可以查看版本常量/** * CodeIgniter Version * ...