修改转场的时间值。

如何在执行过程中修改过渡的时间值?例如,我有一个名为“cesta”的对象,以4000ms的时间从左向右移动,然后由于某种原因,我希望更改时间值以使其移动更快。

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
        --从这里更改时间值“从4000到2000”
    end
end
点赞
用户869951
用户869951

文档在 http://docs.coronalabs.com/api/library/transition/index.html 中显示,没有函数调用来完成此操作。因此,您需要取消当前未完成的转换并创建一个新的转换。例如,

local trans
local transTime = 4000 -- 毫秒
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

这显示了一个生成函数,在其中创建显示对象并通过转换将其移动到某个 x,并且将在某个时刻调用事件处理程序。它计算出转换中剩余的时间,如果 > 0,则创建一个新的转换,使 x 的“运动”速度加倍的一半。

2014-06-04 01:33:20