Modify the time value of a transition

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

I don’t believe you can change it on the fly, but you can cancel it and then create a new one starting from the existing point of the object.

The transition.to() call returns a “handle” to that transition that can then be used to cancel it. So when you create the transition you could do this:

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

Then if you need to cancel it you can grab that and cancel it:

transition.cancel( cesta.trans ) -- new transition.to goes here

Hopefully that will get you going.

 Jay

Thank you!! that looks better.

I’ve done this with timer.performwithdelay and I assume that it would work with transition. to

when you get the handle of the transition.to  there’s a variable called _duration. (It’s called _delay when using timer.performwithdelay. )

You should be able to change the duration without having to cancel and re-start the transition. 

So cesta.trans._duration = 2000 maybe?  I’ve done this in a game where you can speed up and slow down the game clicking on a 1x/2x button. 

I believe properties that start with an underline like _duration are considered “private” and thus Corona Labs could change or kill at any time. So use those at your own risk.

 Jay

I don’t believe you can change it on the fly, but you can cancel it and then create a new one starting from the existing point of the object.

The transition.to() call returns a “handle” to that transition that can then be used to cancel it. So when you create the transition you could do this:

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

Then if you need to cancel it you can grab that and cancel it:

transition.cancel( cesta.trans ) -- new transition.to goes here

Hopefully that will get you going.

 Jay

Thank you!! that looks better.

I’ve done this with timer.performwithdelay and I assume that it would work with transition. to

when you get the handle of the transition.to  there’s a variable called _duration. (It’s called _delay when using timer.performwithdelay. )

You should be able to change the duration without having to cancel and re-start the transition. 

So cesta.trans._duration = 2000 maybe?  I’ve done this in a game where you can speed up and slow down the game clicking on a 1x/2x button. 

I believe properties that start with an underline like _duration are considered “private” and thus Corona Labs could change or kill at any time. So use those at your own risk.

 Jay