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

来源:互联网 发布:腾讯数据库有多大 编辑:程序博客网 时间:2024/05/17 05:14

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

        return callback(event)

    end, isMultiTouches, 0, swallowTouches)

    self:setTouchEnabled(true)

    return self

end



0 0
原创粉丝点击