注册触摸事件:
function RankCenterPanel:registerTouchListener()
local listener = cc.EventListenerTouchOneByOne:create()
listener:setSwallowTouches(true)
listener:registerScriptHandler(function(touch, event)
return self:onTouchBegan(touch, event)
end, cc.Handler.EVENT_TOUCH_BEGAN)
listener:registerScriptHandler(function(touch, event)
self:onTouchEnded(touch, event)
end, cc.Handler.EVENT_TOUCH_ENDED)
ls.Director:getEventDispatcher():addEventListenerWithFixedPriority(listener, -1)
self._touchListener = listener
end
初始化调用:self:registerTouchListener()
取消触摸事件:
function RankCenterPanel:unregisterTouchListener()
ls.removeEventListener(self._touchListener)
self._touchListener = nil
end
local function onTouchBegan(touch, event)
local touchPos = s