Cocos 2d-x 3.6 touch事件只有began 坑~

前端之家收集整理的这篇文章主要介绍了Cocos 2d-x 3.6 touch事件只有began 坑~前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

touch事件只有began

-- add touch layer

display.newLayer()

:onTouch(handler(self,self.onTouch))

:addTo(self)

少了这个return,让哥的touch事件只有began,framework就是这么菜


cocos\framework\extends\LayerEx.lua

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[1]

local points = {}

for i = 1,#args,3 do

local x,y,id = args[i],args[i + 1],args[i + 2]

points[id] = {x = x,y = y,id = id}

end

event.points = points

else

event.x = args[1]

event.y = args[2]

end

returncallback(event)

end,宋体"> self:setTouchEnabled(true)

return self

end

猜你在找的Cocos2d-x相关文章