【问题标题】:Modify the time value of a transition修改过渡的时间值
【发布时间】:2014-06-04 09:33:20
【问题描述】:

如何在执行时更改转换的时间值?例如,我让对象“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

【问题讨论】:

    标签: lua 2d coronasdk transition


    【解决方案1】:

    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,则创建一个新的过渡,剩余时间只有一半,因此 x 的“运动”速度加倍。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多