coronasdk - 检测 Corona SDK 中每个多点触控事件的 X 和 Y

标签 coronasdk multi-touch touch-event

在 Corona SDK 中激活多点触控后,有没有办法可以跟踪每个同时触摸的 x 和 y 坐标?
理想的函数应该是这样的:
local function detectMultitouch(touches)<br/> for i = 0, #touches do<br/> print(touches[i].x .. " ".. touches[i].y) end<br/> end

最佳答案

你可以试试这个

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)

关于coronasdk - 检测 Corona SDK 中每个多点触控事件的 X 和 Y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18408772/

相关文章:

android - 如何在 Corona SDK 中创建加载屏幕?

macos - 如何判断 MTDeviceRef 是什么类型的多点触控设备

linux - linux支持多点触摸屏吗

java - webView.ontouch和button.onclick之间的冲突

javascript - 可以使用 hammer.js 平移事件并仍然允许用户滚动吗?

objective-c - UIScrollview 在 iphone sdk 中滚动时如何添加声音?

lua - 有没有办法从 ScrollView 小部件中删除项目?

android - 如何使用 Corona SDK 将分享功能添加到 Android 应用程序?

ruby-on-rails - 如何从另一个应用程序向 Ruby on Rails 发送 http 请求?

Android 多点触控 : Pointers with index > 0 not triggering event. Action_Move