在 corona sdk 中旋转对象

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

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)

如何实现?

点赞
用户14329040
用户14329040

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

需要注意的是,需要有两个不同的对象来表示白色部分和彩色部分(抱歉,我不知道具体名称)。

这样白色部分就不动,而你可以通过特定的数字来修改彩色部分的 x 和 y 坐标。这些数字根据之前获取的信息不同而不同。

2020-12-12 20:55:24