cocos2d-x学习笔记之touch分发器1
来源:互联网 发布:mac解压rar软件 编辑:程序博客网 时间:2024/06/05 23:46
原文地址:cocos2d-x学习笔记之touch分发器1作者:zjia5
cocos2d-x学习笔记之touch分发器1
openglView的时候注册的:
1
2
3
4
5
6
7
8
9
10
11
//1、直接设置touch分发器
void
CCDirector::setTouchDispatcher(CCTouchDispatcher* pTouchDispatcher)
{
//设置touch分发器
if
(m_pTouchDispatcher != pTouchDispatcher)
{
CC_SAFE_RETAIN(pTouchDispatcher);
CC_SAFE_RELEASE(m_pTouchDispatcher);
m_pTouchDispatcher = pTouchDispatcher;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
//2、导演类初始化的时候创建touch分发器
bool CCDirector::init(
void
)
{
......
//导演类初始化的时候生成touch分发器
m_pTouchDispatcher =
new
CCTouchDispatcher();
m_pTouchDispatcher->init();
... ...
return
true
;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
void
CCDirector::setOpenGLView(CCEGLView *pobOpenGLView)
{
CCAssert(pobOpenGLView,
"opengl view should not be null"
);
if
(m_pobOpenGLView != pobOpenGLView)
{
......
//注册touch分发器到openglView中,接收view传递过来的touch事件
m_pobOpenGLView->setTouchDelegate(m_pTouchDispatcher);
m_pTouchDispatcher->setDispatchEvents(
true
);
}
}
1
2
3
int
m_nId;
CCPoint m_point;
CCPoint m_prevPoint;
CCTouch.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// returns the current touch location in screen coordinates
CCPoint CCTouch::getLocationInView()
const
{
//获取屏幕坐标
return
m_point;
}
// returns the current previous location in screen coordinates
CCPoint CCTouch::getPreviousLocationInView()
const
{
//获取上一次的屏幕坐标
return
m_prevPoint;
}
// returns the current touch location in OpenGL coordinates
CCPoint CCTouch::getLocation()
const
{
//获取在opengl坐标系中的坐标
return
CCDirector::sharedDirector()->convertToGL(m_point);
}
// returns the previous touch location in OpenGL coordinates
0 0
- cocos2d-x学习笔记之touch分发器1
- Cocos2d-x事件分发机制学习笔记
- 小for的Cocos2d-x学习笔记与感悟5之拖动(Touch)事件
- Cocos2d-x学习笔记(九)-------->Touch事件处理机制
- Cocos2d-X 学习笔记 22 CCLayer 界面Touch事件处理
- cocos2d-x学习笔记——EventDispatcher事件分发机制
- Cocos2D-X 之 Touch事件
- Cocos2d-x之Touch事件
- [Cocos2d-x 2.3]Touch操作事件是如何分发的
- Cocos2d-x学习笔记之Cocos2d-x开发环境搭建
- 学习cocos2d-x笔记-1
- cocos2d-x 学习笔记1
- cocos2d-x 学习笔记1
- Cocos2d-x学习笔记1
- Cocos2d-x学习笔记1
- cocos2d-x学习笔记(1)
- cocos2d-x-3.1 事件分发机制 (coco2d-x 学习笔记七)
- 学习笔记cocos2d-x之项目分析
- 用Delphi获取当前系统时间
- 远程控制 远程监控软件2013年终极排行榜
- VC默认的字体
- Why the "volatile" type class should not be used
- 使用larbin网络爬虫的问题
- cocos2d-x学习笔记之touch分发器1
- OSA开源管理平台
- linux进程后台运行
- IP,子网,掩码检查以及生成-----python安装包
- 关于升级ADT之后Eclipse无法开启的问题
- IOS图标尺寸一览
- Java使用管道实现进程间通讯
- 全国人大常委会今起将审议“单独两孩”政策
- Win7环境下VS2010配置Cocos2d-x-2.1.4最新版本的开发环境(亲测)