怎么判断手指在屏幕上面水平移动超过100px
local function onTouchBegin(touch, event)
local location = touch:getLocation()
touchBeginPoint = {x = location.x, y = location.y}
return true
end
local function onTouchMoved(touch, event)
local location = touch:getLocation()
if (location.x - touchBeginPoint.x > 100) then
print("手指向右移动了100px")
elseif location.x - touchBeginPoint.x < -100 then
print("手指向左移动了100px")
end
end
local function onTouchEnded(touch, event)
local location = touch:getLocation()
touchBeginPoint = nil
end
local layer = cc.Layer:create()
local listener = cc.EventListenerTouchOneByOne:create()
-- local listener = cc.EventListenerTouchAllAtOnce:create() --多点
listener:registerScriptHandler(onTouchBegin,cc.Handler.EVENT_TOUCH_BEGAN )
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
local layerFarm = cc.Director:getInstance()
local eventDispatcher = layerFarm:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
self.childPanel:addChild(layer)