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