2013-08-23 3 views
2

После активации мультитача в SDK Corona, есть ли способ отслеживать координаты x и y каждого одновременного касания?
Идеальная функция будет выглядеть так:
local function detectMultitouch(touches)
for i = 0, #touches do
print(touches[i].x .. " ".. touches[i].y) end
end
Обнаружение X и Y каждого события Multitouch в Corona SDK

+0

Где вы хотите использовать мультитач? – NaviRamyle

ответ

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) 
Смежные вопросы