【问题标题】:Rotate objects in the corona sdk在 corona sdk 中旋转对象
【发布时间】:2020-11-16 21:30:20
【问题描述】:

在我的游戏中有两个对象(眼睛),我需要让它们朝着点击屏幕的方向转动。我在互联网上找到了一个示例监听器,但它是用于多点触控的,我需要单点触控。

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)

如何实现?

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    我的建议是使用event.xevent.y 来获取触摸坐标。然后你可以将它们与眼睛坐标进行比较。

    这表示白色部分和彩色部分必须有 2 个不同的对象(抱歉,我不知道具体名称)。

    这样白色部分保持静止,您可以通过特定数字修改彩色部分的 x 和 y。根据您之前获得的信息,这些数字会有所不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-18
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多