내 게임에서 나는 터치 이벤트를 사용하여 객체를 제어합니다. 화면의 오른쪽 절반을 만질 때, 물체가 회전하고 화면의 왼쪽 절반을 만질 때 물체가 움직입니다. 그것은 단 한 번의 터치 일 때 완벽하게 작동하지만, 화면의 어느 한면을 터치하고 동시에 다른면을 터치하기 시작하면 예기치 못한 혼합 된 동작이 발생합니다.다중 터치 감지
내 질문은 분리 또는 여러 터치를 구별하는 방법입니다.
system.activate("multitouch")
onTouch = function (event)
if (event.phase == "began") then
pX = event.x -- Get start X position of the touch
print("ID:"..tostring(event.id))
if (event.x > centerX) then --if the touch is in the right or left half of the screen
xPos = "right"
else
xPos = "left"
end
elseif (event.phase == "moved") then
local dX = (event.x - pX)
if (xPos == "right") then
rotatePlayer(dx)
else
movePlayer(dX)
end
업데이트 :
system.activate("multitouch")
local touchID = {} --Table to hold touches
onTouch = function (event)
if (event.phase == "began") then
print("ID:"..tostring(event.id))
if (event.x > centerX) then --if the touch is in the right or left half of the screen
touchID[event.id] = {}
touchID[event.id].x = event.x
xPos = "right"
pX = touchID[event.id].x -- Get start X position of the touch
else
touchID[event.id] = {}
touchID[event.id].x = event.x
xPos = "left"
pX = touchID[event.id].x
end
elseif (event.phase == "moved") then
print("ID:"..tostring(event.id))
local dX
if (xPos == "right") then
touchID[event.id].x = event.x
dX = touchID[event.id].x - pX
rotatePlayer(dx)
else
touchID[event.id].x = event.x
dX = touchID[event.id].x - pX
movePlayer(dX)
end
같은 문제는 여전히 존재합니다.
터치 ID를 테이블에 추가하고 터치로 이동 시키려고했지만 동일한 문제가 여전히 존재합니다. 업데이트 된 질문을 확인하십시오. – Abdou023