Requesting timescale in timers and transitions

ok just updated file. it was an easy fix to have it delay the timeScale automatically. also added the ability to use trans:timeScale(0.5). slightly different demo file to play with. enjoy and let me know of any other issues you come across.

also added a version number to top of code and zip filename to make it easier to know if you have the newest version. current version i called 0.3

trans:timeScale is nice addition.

I do think that the timeScaling of transition should also scale the delay param in the transition. What do you think?

done. version 0.31 uploaded

Some problem with delay in 31.

This code:

[lua]require’_apiExtend’

local ball = display.newCircle( 20, 20, 10 )

local trans = transition.to( ball, {delay = 5000, time = 20000, x = 300, onComplete = function()

                ball.fill = {1,0,0,1} 

                end } )

trans:timeScale(0.5)[/lua]

Gives you:

Runtime error

/Users/jonjonsson/Downloads/_apiExtend0_31/_apiExtend.lua:41: attempt to perform arithmetic on global ‘ts’ (a nil value)

stack traceback:

    /Users/jonjonsson/Downloads/_apiExtend0_31/_apiExtend.lua:41: in function ‘timeScale’

    /Users/jonjonsson/Downloads/_apiExtend0_31/main.lua:9: in main chunk

sorry move line 29 to just above function new:timeScale(…)

updating file now

0.32 gives error on this code

[lua]display.setStatusBar( display.HiddenStatusBar )

require’_apiExtend’

local seconds = display.newText(“0”, 100, 100)

local x = 1

timer.performWithDelay( 1000, function() seconds.text = x; x = x + 1 end, 0)

local ball = display.newCircle( 20, 20, 10 )

local trans = transition.to( ball, {delay = 4000, time = 4000, x = 300, onComplete = function()

                ball.fill = {1,0,0,1} 

                end } )

trans:timeScale(0.5)[/lua]

This should start the ball at 2 seconds and complete everything in 4 seconds right? I put a seconds counter as well.

This code gives error:

Runtime error

/Users/jonjonsson/Downloads/_apiExtend0_32/_apiExtend.lua:32: bad argument #1 to ‘pairs’ (table expected, got nil)

stack traceback:

    [C]: in function ‘pairs’

    /Users/jonjonsson/Downloads/_apiExtend0_32/_apiExtend.lua:32: in function ‘_listener’

    ?: in function <?:141>

    ?: in function <?:218>

I have to go out for the day, I’ll give it ago again tonight or in the morning. 

ok I know what’s wrong. will take me a bit to correct

version 0.33 uploaded. i had to add a 30millisecond delay to give the keysStart table time to be created. i tested with my main and your main seems to be working now

There are still some problems with delay, not errors but functioning not quite as expected. See comments in code. Maybe its not worth supporting delay, its up to you :slight_smile:

[lua]display.setStatusBar( display.HiddenStatusBar )

require’_apiExtend’

local seconds = display.newText(“0”, 100, 100)

local x = 1

timer.performWithDelay( 1000, function() seconds.text = x; x = x + 1 end, 0)

local ball = display.newCircle( 20, 20, 10 )

local trans = transition.to( ball, {delay = 4000, time = 4000, x = 300, onComplete = function()

                ball.fill = {1,0,0,1} 

                end } )

– Starts at second 4 correctly but remaining should be 2 seconds for 6 total (is 8)

timer.performWithDelay(4000, function() trans:timeScale(0.5) end)

– This should start at second 3 instead of 2

–timer.performWithDelay(2000, function() trans:timeScale(0.5) end)[/lua]

Can you provide a better description?

Thanks

Rob

I’m requesting what is already done with animations: https://docs.coronalabs.com/api/type/SpriteObject/timeScale.html

Let’s suppose we’ve this piece of code

timer.performWithDelay(1000, someFunction)

“someFunction” will be executed a second later, but if there was a “timeScale” property setted to 0.5, that function would be executed not just a second later, but after 2 seconds

You can to go http://feedback.coronalabs.com and add an entry for this and get people to vote it up.

Rob

why not just do

local timeScale =1
local time = timer.performWithDelay((1000*timeScale), someFunction)

then adjust as needed

Thank you @Rob!

@jstrahan that’s so simple, but I’m not requesting this, I would love something like this:

local timerId = timer.performWithDelay(1000, someFunction) timer.performWidthDelay(500, function() timer.setTimeScale(timerId, 0.5) end)

If the second function [timer.setTimeScale] existed, the “someFunction” would be executed in 1.5 seconds in total. What I’m asking for is the possibility to set the timeScale whenever I want, not just at the beggining

And not just for timers, but for transitions too!

I could really use this feature with a Fast Forward button in my game. Will give it max upvotes if you make the feature request.

ok i have a timescale function for timers starting on transitions in a bit. will post code in a bit

Cool, looking forward to it :slight_smile:

heres a look at the api that i have. if you have any suggestions let me know. transition.timeScale works with transition.to havent tested on other transition.

Note that since these api’s will be using undocumented variables it could be broken by changes made by CoronaLabs

to use require file like this

require ‘_apiExtend’

then you can use these new functions

timer.timeScale( timerId, timeScale )

transition.timeScale( transId, timeScale )

and you can read the current timeScale by

timerId.timeScale

transId.timeScale

if nil is returned then the timeScale has not been changed so it would be 1

link to code coming in a bit.

here’s the link.

http://j-strahan.com/main2/_apiextend-lua/

Thanks, I will give it a try soon and report back.