首先要创建一个layer,设置该层为可触摸
layer:setTouchEnabled(true)
注册触摸事件
local listener = cc.EventListenerTouchOneByOne:create()
listener:setSwallowTouches(true)
listener:registerScriptHandler(function(touch, event)
--做触摸处理...
return true--返回true时,该层下面的层的触摸事件都会屏蔽掉
end,cc.Handler.EVENT_TOUCH_BEGAN)
local eventDispatcher = layer:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
时间: 2024-10-06 04:02:54