2012-02-04 6 views
1

화면이 터치되고 있는지 어떻게 알 수 있습니까? 화면이 터치되고 손가락이 움직이지 않는 동안 터치 이벤트는 생성되지 않습니다.Corona SDK : 터치 이벤트

답변

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) 
에 터치 이벤트를 수신 할