cocos2d-x v3.x Lua 中 [cc.Layer] 如何不让触摸事件向下转递

cocos2d-x v3.x Lua 中 [cc.Layer] 如何不让触摸事件向下转递,第1张

概述cocos2d-x 3.3 代码: --比倍界面层local BiBeiLayer = class("BiBeiLayer", function () return cc.LayerColor:create(cc.c4b(0,0,0,125))end)--初始化function BiBeiLayer:ctor() -- 创建一个事件监听器类型为 OneByOne

cocos2d-x 3.3

代码:

--比倍界面层local BiBeiLayer = class("BiBeiLayer",function ()    return cc.Layercolor:create(cc.c4b(0,125))end)--初始化function BiBeiLayer:ctor()        -- 创建一个事件监听器类型为 OneByOne 的单点触摸    local  Listenner = cc.EventListenertouchOneByOne:create()        -- ture 吞并触摸事件,不向下级传递事件;    -- fasle 不会吞并触摸事件,会向下级传递事件;    -- 设置是否吞没事件,在 ontouchBegan 方法返回 true 时吞没    Listenner:setSwallowtouches(true)        -- 实现 ontouchBegan 事件回调函数    Listenner:registerScriptHandler(function(touch,event)        local location = touch:getLocation()        print("EVENT_touch_BEGAN")        return true    end,cc.Handler.EVENT_touch_BEGAN )        -- 实现 ontouchmoved 事件回调函数    Listenner:registerScriptHandler(function(touch,event)        local locationInNodeX = self:convertToNodeSpace(touch:getLocation()).x             print("EVENT_touch_MOVED")    end,cc.Handler.EVENT_touch_MOVED )        -- 实现 ontouchended 事件回调函数    Listenner:registerScriptHandler(function(touch,event)        local locationInNodeX = self:convertToNodeSpace(touch:getLocation()).x        print("EVENT_touch_ENDED")    end,cc.Handler.EVENT_touch_ENDED )    local eventdispatcher = self:getEventdispatcher()    -- 添加监听器    eventdispatcher:addEventListenerWithSceneGraPHPriority(Listenner,self)end
总结

以上是内存溢出为你收集整理的cocos2d-x v3.x Lua 中 [cc.Layer] 如何不让触摸事件向下转递全部内容,希望文章能够帮你解决cocos2d-x v3.x Lua 中 [cc.Layer] 如何不让触摸事件向下转递所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1010676.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存