又一个触摸事件,哟
2016-04-10 18:19
381 查看
1.触摸事件,~对ccTouchMove,和ccTouchEnded过程的
void AutoSet::ccTouchMoved(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){CCPoint beginPoint=pTouch->getLocationInView();
//将触摸点坐标转换为opengl坐标
beginPoint=CCDirector::sharedDirector()->convertToGL(beginPoint);
//取得标签的位置
CCPoint pt=text->getPosition();
CCRect rect=CCRectMake(pt.x-30,pt.y-30,60,60);
if(rect.containsPoint(beginPoint)){
//得到触摸前面的一个点。
CCPoint endPoint=pTouch->getPreviousLocationInView();
//转换一下
endPoint=CCDirector::sharedDirector()->convertToGL(endPoint);
CCPoint offSet=ccpSub(beginPoint,endPoint);
CCPoint toPoint=ccpAdd(text->getPosition(),offSet);
text->setPosition(toPoint);
}
}
void AutoSet::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){
CCPoint lastPoint=pTouch->getLocationInView();
lastPoint = CCDirector::sharedDirector()->convertToGL(lastPoint);
CCRect Rect=CCRectMake(330,130,60,60);
CCMoveTo*moveTo;
if(!Rect.containsPoint(lastPoint)){
moveTo=CCMoveTo::create(0.1f,ccp(120,160));
}
else{
moveTo=CCMoveTo::create(0.1f,ccp(360,160));
}
text->runAction(moveTo);
}
自己做出点东西还是蛮快乐的。可是希望宿舍的门早点开啊。别冻死我啊
相关文章推荐
- 用例
- ubuntu中安装Rstdio无法切换中文输入法
- 采用maven 对tomcat 进行自动部署
- ppt整体配色方案
- The 16th Zhejiang University Programming Contest - E
- Scrapy设置之Downloading media
- 编译安装LAMP(一)
- EasyDarwin安卓直播之EasyPusher NDK开发:JNI回调函数的实现
- uva 340 Master-Mind Hints
- POJ 2456 Aggressive cows (贪心 + 二分)
- SVN需求文档的完善
- Xcode pch文件配置相对路径方法
- Android实训案例(六)——四大组件之一BroadcastReceiver的基本使用,拨号,短信,SD卡,开机,应用安装卸载监听
- Android实训案例(六)——四大组件之一BroadcastReceiver的基本使用,拨号,短信,SD卡,开机,应用安装卸载监听
- Openstack学习笔记(七)-在Win环境下通过XManager(xshell)远程打开eclipse
- Modsecurity原理分析--从防御方面谈WAF的绕过(一)
- 【SSM-MyBatis框架】Mapper.xml配置文件(mybatis的核心)
- 谷歌希望让 Swift 成为安卓的优先选择,以取代由 Oracle 开发的 Java 程序语言。
- CentOS6.5系统双网卡绑定配置详解
- iOS内存管理机制解析之MRC手动引用计数机制