我正在 Corona 中制作游戏,但遇到了问题。我在屏幕上有一个圆圈,我希望它连续跟随触摸坐标。我正在使用 transition.to 函数来执行此操作,但问题是,每当此函数获得坐标时,即使坐标在转换期间更新,它也会完成转换。
if event.phase == "began" or event.phase == "moved" then
follow = true
touchX = event.x; touchY = event.y
elseif event.phase == "ended" then
follow = false
end
在另一个函数中,我正在这样做
if follow == true then
transition.to(circle, {time = 500, x = touchX, y = touchY, transition = easing.inOutQuad})
end
该代码对于简单的触摸效果很好,但我希望圆圈即使在移动时也能跟随触摸。
最佳答案
有一些示例可以解决您的问题。
引用:
1) Flight Path卡洛斯在 Corona 社区中发布。
2) Move Object through a path通过雷维斯
示例:
local circle = display.newCircle(10,10,20)
circle.x = 160
circle.y = 160
local olderTransition
local function moveCircle(e)
if olderTransition ~= nil then
transition.cancel( olderTransition )
end
olderTransition = transition.to(circle,{time=100,x=e.x,y=e.y})
end
Runtime:addEventListener("touch",moveCircle)
继续编码............:)
关于lua - 转换时更新目标坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17692103/