优先级更改


function UIAdapter:transNode(luaNode,isSwallowTouches)
    local function checkVisible(node)
        if node:isVisible() == false then
            return false
        elseif node.getParent and node:getParent() then
            return checkVisible(node:getParent())
        end
        return true
    end
    local isSwallowTouches = isSwallowTouches
    if isSwallowTouches == nil and luaNode.isTouchSwallowEnabled then
        isSwallowTouches = luaNode:isTouchSwallowEnabled()
    end
    if isSwallowTouches == nil then
        isSwallowTouches = true
    end
    if luaNode._scriptEventListeners_==nil or luaNode._scriptEventListeners_[cc.NODE_TOUCH_EVENT]==nil then
        return
    end
    luaNode:setTouchEnabled(false)
    luaNode._touchEnabled = false
    function luaNode.onTouchBegan (touch, unusedEvent)
        local event = {name="began",
            x=touch:getLocation().x,
            y=touch:getLocation().y,
            prevX=touch:getPreviousLocation().x,
            prevY=touch:getPreviousLocation().y,
            }
        local inArea = luaNode._touchEnabled and checkVisible(luaNode) and luaNode:getCascadeBoundingBox():containsPoint(touch:getLocation())
        -- print(luaNode:convertToWorldSpace(cc.p(luaNode:getPosition())).x)
        -- print(touch:getLocation().x)
        -- print(luaNode:convertToWorldSpace(cc.p(luaNode:getPosition())).y)
        -- print(touch:getLocation().y)
        if inArea then
            luaNode:EventDispatcher(cc.NODE_TOUCH_EVENT,event)
        end
        return inArea
    end
    function luaNode.onTouchMoved (touch, unusedEvent)
        local event = {name="moved",
            x=touch:getLocation().x,
            y=touch:getLocation().y,
            prevX=touch:getPreviousLocation().x,
            prevY=touch:getPreviousLocation().y,
            }
        local inArea = luaNode._touchEnabled --and luaNode:getCascadeBoundingBox():containsPoint(touch:getLocation())
        if inArea then
            luaNode:EventDispatcher(cc.NODE_TOUCH_EVENT,event)
        end
    end
    function luaNode.onTouchEnded (touch, unusedEvent)
        local event = {name="ended",
            x=touch:getLocation().x,
            y=touch:getLocation().y,
            prevX=touch:getPreviousLocation().x,
            prevY=touch:getPreviousLocation().y,
            }
        local inArea = luaNode._touchEnabled --and luaNode:getCascadeBoundingBox():containsPoint(touch:getLocation())
        if inArea then
            luaNode:EventDispatcher(cc.NODE_TOUCH_EVENT,event)
        -- else
        --  event.name="cancelled"
        --  luaNode:EventDispatcher(cc.NODE_TOUCH_EVENT,event)
        end
    end
    function luaNode.onTouchCancelled (touch, unusedEvent)
        local event = {name="cancelled",
            x=touch:getLocation().x,
            y=touch:getLocation().y,
            prevX=touch:getPreviousLocation().x,
            prevY=touch:getPreviousLocation().y,
            }
        if luaNode._touchEnabled then
            luaNode:EventDispatcher(cc.NODE_TOUCH_EVENT,event)
        end
    end
    function luaNode:setTouchEnabled(enable)
        if enable == self._touchEnabled then
            return
        end
        local _eventDispatcher = cc.Director:getInstance():getEventDispatcher()
        self._touchEnabled = enable
        if (self._touchEnabled) then
            self._touchListener = cc.EventListenerTouchOneByOne:create()
            self._touchListener:setSwallowTouches(isSwallowTouches)
            self._touchListener:registerScriptHandler(self.onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN)
            self._touchListener:registerScriptHandler(self.onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED)
            self._touchListener:registerScriptHandler(self.onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED)
            self._touchListener:registerScriptHandler(self.onTouchCancelled,cc.Handler.EVENT_TOUCH_CANCELLED)
            _eventDispatcher:addEventListenerWithSceneGraphPriority(self._touchListener,self)
        else
            _eventDispatcher:removeEventListener(self._touchListener)
        end
    end
    luaNode:setTouchEnabled(true)
    return luaNode
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值