2012-02-04 109 views

回答

0

是的,只有變化到手指移動記錄。放下手指,舉起手指並拖動觸發事件。

0

但是,你可以在你的事件函數做

e.phase == "began" 

。當用戶將手指放在屏幕上時,會觸發這種情況。

0

觸摸事件分階段處理。因此觸摸產生的事件已經「開始」,「移動」,「結束」和「取消」階段。你可以使用的檢測,因此,這樣做:

self.isTouched = false; 

function defaultTouchHandler(e) 
    if(e.phase == "began") then 
     print("Tapped") 
     self.isTouched = true; 
     --User has touched the screen (not moving). Do "onMouseDown" things here 
    elseif(e.phase == "moved") then 
     print("Moved") 
     --User is moving their finger wile touching. Do "onMouseMoved" things here 
    elseif(e.phase == "cancelled" or e.phase == "ended") then 
     print("End of touch") 
     self.isTouched = false; 
     --User lifted their finger, or an interrupt happened. Do "onMouseUp" things here 
    end 
end 

self:addEventListener("touch", defaultTouchHandler) 

當你再需要檢查,如果屏幕被觸摸,簡單地做:

if(isTouched) then 
    --Screen is being touched 
else 
    --Screen is not being touched 
end 

編輯:很明顯,你可以改變「自我」在addEventListener行可以成爲任何你想要聽的觸摸事件的對象

0
local object = display.newImage("ball.png") 
object.id = "ball object" 

local function onObjectTouch(event) 
if (event.phase == "began") then 
    print("Touch event began on: " .. event.target.id) 
elseif (event.phase == "ended") then 
    print("Touch event ended on: " .. event.target.id) 
end 
return true 
end 
object:addEventListener("touch", onObjectTouch)