touch事件过程

扫码查看
local function onTouchBegan(touch, event)
  local point = touch:getLocation() --获取touch位置,         基于openGL坐标
  local point = touch:getPreviousLocation() --获取前一次touch位置       基于openGL坐标
  local point = touch:getStartLocation() --获取touch起始位置        基于openGL坐标
  local point = touch:getDelta() --获取前后两次位置的偏移量     基于openGL坐标
  local point = touch:getLocationInView() --当前touch位置      基于屏幕坐标位置
  local point = touch:getPreviousLocationInView() --前一次位置 基于屏幕坐标位置
local point = touch:getStartLocationInView()--获取起始位置 基于屏幕坐标位置
end local function onTouchMoved(touch, event)
end local function onTouchEnded(touch, event)
end local listener = cc.EventListenerTouchOneByOne:create()
listener:setSwallowTouches(true)
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self) --eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)中的第二个参数,决定了touch事件,点击的目标,在整个屏幕中点击的永远为self所指的node
04-16 07:07
查看更多