修改转换的时间值

时间:2014-06-03 23:21:27

标签: lua 2d corona transition

如何在执行时更改转换的时间值?例如,我将对象“cesta”从左向右移动4000毫秒然后由于某种原因我想更改时间值以更快地移动它。

function createCesta()
    ...
    transition.to(cesta, {time = 4000, x = screenW + 110})
    ...
end


function touchScreen(event)   
    if event.phase == "began" then
    end
    if event.phase == "ended" then
        --change the time value from here "from 4000 to 2000"
    end
end

1 个答案:

答案 0 :(得分:2)

http://docs.coronalabs.com/api/library/transition/index.html处的文档表明没有函数调用来执行此操作。因此,您必须取消当前未完成的转换并创建一个新转换。例如,

local trans
local transTime = 4000 -- ms
local transStart
local object

function someEventHandler(event)
   transition.cancel(trans)
   local remaining = system.getTimer() - transStart - transTime 
   if remaining > 0 then
       trans = transition.to(object, { time = remaining/2, x = ... }
   end
end

function spawn()
   object = display.newText(...)
   trans = transition.to(object, {time = transTime}
   transStart = system.getTimer()
end

这显示了一个spawn函数,您可以在其中创建一个显示对象并使其通过转换移动到某个x,以及将在某个时刻调用的事件处理程序。它计算转换中剩余的时间以及是否> 0,创建一个新的过渡,剩余时间的一半,所以"运动加倍#34;速度x。

相关问题