私のゲームでは、私はタッチイベントを使ってオブジェクトをコントロールします。画面の右半分に触れるとオブジェクトが回転し、画面の左半分をタッチするとオブジェクトが動きます。ワンタッチでは完全に機能しますが、画面のいずれかの面に触れてからもう一度タッチすると、予期しない混乱した動作になります。複数のタッチを検出する
私の質問は、複数のタッチを別々に区別する方法です。
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