修改过渡的时间值 [英] Modify the time value of a transition

查看:31
本文介绍了修改过渡的时间值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在执行时更改转换的时间值?例如,我让对象cesta"以 4000 毫秒的时间从左向右移动,然后出于某种原因我想更改时间值以使其移动得更快.

How can i change the time value of a transition while is executing? For example I have the object "cesta" moving from the left to the right with a time of 4000ms then for some reason I want to change the time value to move it faster.

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

推荐答案

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

The docs at http://docs.coronalabs.com/api/library/transition/index.html indicate that there is no function call to do this. You would therefore have to cancel the current incomplete transition and create a new one. For example,

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 的运动"速度加倍.

This shows a spawn function where you create a display object and make it move via transition to some x, and an event handler that will get called at some point. It computes how much time is left in the transition and if > 0, creates a new transition with half that remaining time so double the "motion" speed of x.

这篇关于修改过渡的时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆