修改过渡时间值时间

2023-09-07 14:46:15 作者:嫉妒是最诚实的告白

我怎样才能改变一个过渡的时间价值,同时在执行?比如我有对象CESTA从左侧移动到右侧用4000ms的时间,然后由于某种原因,我想改变的时间值,以更快地移动。

 函数createCesta()
    ...
    transition.to(CESTA,{时间= 4000,X = screenW + 110})
    ...
结束


功能触摸屏(事件)
    如果event.phase ==开始,然后
    结束
    如果event.phase ==结束,那么
        时间值--change从这里开始,从4000到2000
    结束
结束
 

解决方案

在 http://docs.coronalabs.com/api/library/transition/index.html 表示没有函数调用来做到这一点。因此,您将不得不取消当前未完成过渡,并创建一个新的。例如,

 本地反
当地transTime = 4000  -  MS
当地transStart
本地对象

功能someEventHandler(事件)
   transition.cancel(反式)
   本地剩余= system.getTimer() -  transStart  -  transTime
   如果剩余> 0,则
       反= transition.to(对象{时间=剩余/ 2,X = ...}
   结束
结束

功能菌种()
   对象= display.newText(...)
   反= transition.to(对象{时间= transTime}
   transStart = system.getTimer()
结束
 

这表示在您创建一个显示对象,使之通过转型移动到有些X的一个菌种功能,以及事件处理程序将调用在一些点。它计算多少时间留在过渡,如果> 0,创建具有一半的剩余时间,从而增加一倍x的运动速度的新的过渡。

pr怎么把过渡时间,设置成固定的值

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

解决方案

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

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.

 
精彩推荐
图片推荐