Cocos2d触摸:单点触摸

前端之家收集整理的这篇文章主要介绍了Cocos2d触摸:单点触摸前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  
  
/* 单点触摸事件 */ // 创建一个怪物 auto guaiwu = Sprite::create("res/tk.png"); guaiwu->setPosition(Point(200,));thisaddChild(guaiwu listener EventListenerTouchOneByOne();// 触摸键开始,当手指按下,怪物移动到点击的坐标位置 listeneronTouchBegan [](Touch* touch Event event){ // 获取单击坐标,基于3d// touch->getLocation();// touch->getLocationInView();//Director::getInstance()->convertToGL(<#const cocos2d::Vec2 &point#>)// 将2d坐标转换成cocos2d-x坐标 Point point DirectorgetInstance()->convertToGLgetLocationInView()// 创建移动对象,并将移动位置设置为当前点击的坐标 moveTo MoveTo0.3f Pointpoint.xy // 取出注册监听时间时所绑定的node对象 target static_cast<Sprite*>(eventgetCurrentTarget());// 开始移动 targetrunActionmoveToreturntrue; };// 触摸滑动事件,当手指在屏幕上滑动onTouchMoved [](Touch Event

单点触摸用的是EventListenerTouchOneByOne 对象。

原文链接:https://www.f2er.com/cocos2dx/339856.html

猜你在找的Cocos2d-x相关文章