过渡时更新目标坐标 [英] Update the target coordinates while transitioning
问题描述
我正在用电晕进行游戏,但遇到了问题.我在屏幕上有一个圆圈,我希望它不断跟随触摸坐标.我正在使用transition.to函数这样做,但事实是,只要此函数获得坐标,即使坐标在转换过程中进行了更新,它也会完成转换.
I am making a game in corona and I am facing a problem. I have a circle on screen and I want it to follow the touch coordinates continuously. I am using transition.to function to do so but the thing is, whenever this function get a coordinate, it completes the transition even if the coordinates are updated during the transition.
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
在另一个功能中,我正在这样做
And in another function, I am doing this
if follow == true then
transition.to(circle, {time = 500, x = touchX, y = touchY, transition = easing.inOutQuad})
end
该代码可以轻松实现简单的触摸,但是我希望圆圈即使在移动时也能跟随触摸.
The code works fine for simple touch but I want the circle to follow the touch even when it's moving.
推荐答案
有一些示例可以解决您的问题.
There are some examples which may solve your problem.
引用:
1)卡洛斯在电晕社区中发布的飞行路径.
1) Flight Path posted by carlos in corona Community.
2)renvis
示例:
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)
继续编码.......:)
Keep Coding.......... :)
这篇关于过渡时更新目标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!