2

Corona SDK でマルチタッチを有効にした後、同時タッチの x 座標と y 座標を追跡する方法はありますか?
理想的な関数は次のようになります。
local function detectMultitouch(touches)
for i = 0, #touches do
print(touches[i].x .. " ".. touches[i].y) end
end

4

1 に答える 1

2

これを試すことができます

system.activate("multitouch")

local touches = {}
local touchIDs = {}

local function detectMultitouch()
    for i = 1, #touchIDs do
        print("#"..i.." "..tostring(touchIDs[i]) .." = "..touches[touchIDs[i]].x..","..touches[touchIDs[i]].y)
    end
end

Runtime:addEventListener("touch",function(event)
    if event.phase == "began" then
        touches[event.id] = {}
        touches[event.id].x = event.x
        touches[event.id].y = event.y
        touches[event.id].coords = display.newText(tostring(event.id).." = "..touches[event.id].x..","..touches[event.id].y,0,0,system.nativeFont,15)
        touches[event.id].coords.x = touches[event.id].x
        touches[event.id].coords.y = touches[event.id].y

        table.insert(touchIDs,event.id)
    elseif event.phase == "moved" then
        touches[event.id].x = event.x
        touches[event.id].y = event.y
        touches[event.id].coords.text = tostring(event.id).." = "..touches[event.id].x..","..touches[event.id].y
        touches[event.id].coords.x = touches[event.id].x
        touches[event.id].coords.y = touches[event.id].y - 20
    elseif event.phase == "ended" then
        touches[event.id].coords:removeSelf()
        touches[event.id] = nil
        table.remove(touchIDs,table.indexOf(touchIDs, event.id))


        detectMultitouch(touches)
    end
end)
于 2013-08-25T14:57:34.213 に答える