今天遇到一个问题,发现在cocos2dx3.4final的LayerEx.lua的源码里面的OnTouch
下面的代码中,我觉得这里的callback(event)有问题,因为如果是“began”事件的话return true会被这句话吞掉,假如后面有moved和ended事件会收不到,我觉得应该改为return callback(event),经过测试确实有这样的问题存在
function Layer:onTouch(callback, isMultiTouches, swallowTouches)
if type(isMultiTouches) ~= "boolean" then isMultiTouches = false end
if type(swallowTouches) ~= "boolean" then swallowTouches = false end
self:registerScriptTouchHandler(function(state, ...)
local args = {...}
local event = {name = state}
if isMultiTouches then
args = args
local points = {}
for i = 1, #args, 3 do
local x, y, id = args*, args*, args*
points = {x = x, y = y, id = id}
end
event.points = points
else
event.x = args
event.y = args
end
callback(event)
end, isMultiTouches, 0, swallowTouches)
self:setTouchEnabled(true)
return self
end
```
***