在我的游戏中,我使用触摸事件来控制对象。当我触摸屏幕的右半部分时,对象旋转,当我触摸屏幕的左半部分时,对象移动。当它是单点触摸时,它可以很好地工作,但是当我触摸屏幕的任何一侧,然后同时开始触摸另一侧时,就会产生意想不到的混合行为。检测多个触摸
我想我的问题是,如何分离或区分多个触摸之一。
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