cocos lua 3.0 触摸事件

前端之家收集整理的这篇文章主要介绍了cocos lua 3.0 触摸事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

原文转自:http://blog.csdn.net/liyoushihaer/article/details/39501665

  1. local function onTouchEnded(touch,event)
  2. local poin = touch:getLocation()
  3. print(" X:")
  4. end
  5. local function onTouchBegan(touch,event)
  6. local tt =touch:getLocation()
  7. print("x",tt.x,"y:",tt.y)
  8. return true -- 必须返回true 后边的move end等才会被处理
  9. end
  10. local function onTouchMoved(touch,event)
  11. local poin = touch:getLocation()
  12. print(" y:")
  13. end
  14. local listener = cc.EventListenerTouchOneByOne:create() -- 单点触摸监听
  15. -- cc.EventListenerTouchAllAtOnce:create() -- 多点触摸
  16. listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN) 前一个参数是回调函数后一个参数是对应事件
  17. listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
  18. listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED)
  19. local dispacher = layerBg:getEventDispatcher()
  20. dispacher:addEventListenerWithSceneGraPHPriority(listener,layerBg) -- 参数 监听器 对象

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