加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos lua 3.0 触摸事件

发布时间:2020-12-14 19:13:29 所属栏目:百科 来源:网络整理
导读:原文转自:http://blog.csdn.net/liyoushihaer/article/details/39501665 local function onTouchEnded(touch,event) local poin = touch:getLocation() print(" X:") end local function onTouchBegan(touch,event) local tt =touch:getLocation() print("x

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

   local function onTouchEnded(touch,event)
        local poin = touch:getLocation()
        print(" X:")
     end 
    
   local function onTouchBegan(touch,event)
    local tt =touch:getLocation()
    print("x",tt.x,"y:",tt.y)
    return true  -- 必须返回true 后边的move end等才会被处理
   end
   
    local function onTouchMoved(touch,event)
      local poin = touch:getLocation()
        print(" y:")
    end
      
   local listener = cc.EventListenerTouchOneByOne:create() -- 单点触摸监听 
    -- cc.EventListenerTouchAllAtOnce:create()  -- 多点触摸
   listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN) 前一个参数是回调函数后一个参数是对应事件
   listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
   listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED)
   local dispacher = layerBg:getEventDispatcher()  
   dispacher:addEventListenerWithSceneGraphPriority(listener,layerBg)  -- 参数 监听器   对象

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读