layer = cc.Layer:create() -- 创建层
-- 事件处理 touch为点击坐标{x, y, id}
local function _onTouch(eventType, touchs)
if eventType == "began" then
self:OnTouchDown(touchs)
elseif eventType == "moved" then
self:OnTouchMove(touchs)
elseif eventType == "ended" then
self:OnTouchUp(touchs)
end
return false
end
-- 注册点击事件
layer:registerScriptTouchHandler(_onTouch)
-- 设置可点击
layer:setTouchEnabled(true)
local function _update(dt)
-- 更新
if true then
self:Update(dt)
end
end
-- 设置定时器方法 优先级0
layer:scheduleUpdateWithPriorityLua(_update, 0)