cocos2dx 2.1.5版本的手势识别
来源:互联网 发布:美工助理是做什么的 编辑:程序博客网 时间:2024/06/03 16:32
看2048的教学,看到手势识别这一块,突然发现问题,就是2.0跟3.0版本的类不同,他有监听函数而我的版本没有,查了半天资料才找到解决办法,特此记录下来:
第一步:
在init方法中,添加设置可触摸
setTouchEnabled(true);
第二部:
重写函数
void HelloWorld::registerWithTouchDispatcher()
{
CCDirector* director = CCDirector::sharedDirector();
director->getTouchDispatcher() ->addTargetedDelegate(this,0,true);
}
bool HelloWorld::ccTouchBegan(cocos2d::CCTouch *touch,cocos2d::CCEvent *event)
{
CCLog("TouchBegin");
CCPoint touchPoint = touch->getLocation();//获取点击位置
firstX = touchPoint.x;
firstY = touchPoint.y;
return true;
}
void HelloWorld::ccTouchEnded(cocos2d::CCTouch *touch,cocos2d::CCEvent *event)
{
CCLog("TouchEnded");
//获取X轴跟y轴的移动范围
CCPoint touchPoint = touch->getLocation();//获取点击位置
endX = firstX-touchPoint.x;
endY = firstY-touchPoint.y;
//判断移动方向,比较x的绝对值和y的绝对值大小
if(abs(endX)>abs(endY)){
//左右
if(endX+5>0){
//左
doLeft();
}
else{
//右
doRight();
}
}
else{
//上下
if(endY+5>0){
//上
doUp();
}
else{
//下
doDown();
}
}
}
- cocos2dx 2.1.5版本的手势识别
- cocos2dx-手势识别
- 【Cocos2dx】手势识别
- android的手势识别
- Android的手势识别
- 手势的识别
- 手势的识别
- Android的手势识别
- Android 手势的识别
- 手势的识别
- 简单的手势识别
- cocos2dx游戏开发之利用多点触摸(实现缩放功能或者简单的手势识别)
- cocos2dx游戏开发之利用多点触摸(实现缩放功能或者简单的手势识别)
- cocos2dx游戏开发之利用多点触摸(实现缩放功能或者简单的手势识别)
- android的手势识别例子
- 理解Android的手势识别
- 理解Android的手势识别
- 理解Android的手势识别
- 提高SQL执行效率的方法有哪些?
- 马士兵语录
- 小游戏练手1——雷速小子
- 1、Android项目框架搭建 (分析需求、整理资料)
- mvn常用命令
- cocos2dx 2.1.5版本的手势识别
- 如何将文件上传到android模拟器sdcard中
- MFC.bsc文件的生成方法及使用方法
- * is not in the sudoers file. This incident will be reported.
- Cocos2d-x学习笔记(8)
- 个人DLL探究学习记录
- C语言str系列库函数之strspn()、strcspn()和strpbrk()
- MFC的运行机制
- uboot中gd的定义和使用