No one is concerned that a particular timer can not be resumed?
Why does the API has methods Timer.pauseAll () - Timer.resumeAll (), has a method Timer:pause(), but method Timer:resume() is absent?
This leads, for example, that after the call pauseAll(), even newly created and starting timers are not running.
It would be desirable to have a mechanism for pause and resume of a particular timers.
Why do we need methods Timer:stop and Timer:reset? Now, if we can not call the resume(), the two methods are essentially the same...
Comments
You need to use Timer:reset() to reset the timer and start it from the beginning
Likes: AniketK
if (timer ~= nil and timer:isRunning() == true) then
timer:stop()
timer._suspended = true
end
end
function isTimerSuspended(timer)
return timer ~= nil and timer._suspended ~= nil and timer._suspended == true
end
function resumeTimer(timer)
if (isTimerSuspended(timer) == true) then
timer:start()
timer._suspended = false
end
end
Then i do stopTimer(self.MyTimer)
and resumeTimer(self.MyTimer)
And it starts from the beginning
local t = Timer.new(5000)
function test()
print("hello, world")
end
t:addEventListener(Event.TIMER, test)
stage:addEventListener(Event.MOUSE_DOWN, function()
if t:isRunning() then
t:stop()
print("stoped")
else
t:start()
print("started")
end
end)
t:start()
Stop timer every 4 seconds, and you never see "hello, world" print
The timer will start from the beginning of the tick.
local t = Timer.new(5000)
function test()
print("hello, world")
end
t:addEventListener(Event.TIMER, test)
local paused = false
stage:addEventListener(Event.MOUSE_DOWN, function()
if paused == false then
Timer.pauseAll()
print("stoped")
paused = true
else
Timer.resumeAll()
print("started")
paused = false
end
end)
t:start()
maybe no one just requested the feature before
And what about this "after the call pauseAll(), even newly created and starting timers are not running."
This is expected behavior or not? As for me, I did not expect this.
But as the user of API, I wonder why if I were in the one scene, clicked on pause (called pauseAll), and then went to another menu scene... And then I see that at this scene all created timers are stopped.. I find it illogical. I create a new timer - so I know what I'm doing and it should work...
Of course, to fix it - I can just add resumeAll to the constructor of scene base class.
Imagine that I have put the game on pause. And then in the pause menu'm trying to use a timer. It will not work ...
But about scenes, well there is no way for timer to know if the scene has changed, in the end scene is just a sprite object added and removed from stage and does not differ from any other sprite object.
You can come up with different example when you want to pause all timers except one. or start a new timer after a rest stop.
In any case - is uncomfortable constraint.
And well, I think that if it is stated pauseAll, then it means to pause all, even new ones.
In case when you will want a specific Timer to run, you would have to stop all others one by one.
If I had the opportunity to pause timers, one by one, I would have done. Stop them - does not suit me.
But if I need to call a function every 5 seconds .. what could be better than a timer? Why should I do special counters and additional conditions in onEnterFrame.
And I do not understand what is wrong can happen if add resume and pause methods to timer.
If you don't experience anything, than most probably it is ok, maybe even something was updated in Gideros to make them work better.
About pause/resume as I said, I'll discuss it with @atilim
something like this
If I have a power up that lasts for 8 seconds and I pause and resume at 7 seconds using Timer:pauseAll() and Timer:resumeAll() it will behave properly. When it resumes the power up will last 1 more second and then end.
However, if I pause and resume that individual power up timer using Timer:stop() and Timer:start() it will run for another 8 seconds when resumed. If I pause and resume it every 7 seconds it will run indefinitely.
I'm using literally hundreds of timers for sprite animations and have never seen a performance hit. For the same reason, I don't always want to pauseAll but rather pause individual timers. Is there any chance of getting this fixed?
Likes: asakharov
For myself, I developed new Timer based on OnEnterFrame event. Productivity gains have not noticed, but I reached my goal with constistent pausing and resuming.
Likes: Platypus
Likes: Platypus
Here is something kind of sketchy I came up with today. Its a class that extends the regular timer class but adds the pause functionality. Might be hard to understand reasons for some of the code but I found a small bug regarding manipulating a Timer object within its own event listener ( Maybe something to do with threads?)
The class also has a feature you can specify with an additional 3rd table with extra keys.
Current supported feature is a new event called Event.TIMER_INFO which can be enabled via "enterFrameUpdates" key being true in the optional table.
Example code:
Excuse any terrible writing above, I'm very tired
https://play.google.com/store/apps/developer?id=Into-It+Games
http://appstore.com/LidiaMaximova
Fixed (I think!) bug where Event.TIMER_INFO event get negative values for looping timers. Also fixed issue with changing the timer delay. Current implementation lets the current "run" with old delay to finish, and then sets the new delay. I plan on making the setDelay function simply extend the time, but I will need to experiment how the native Gideros function works.
Question to Gideros Team:
Does calling Timer:setDelay(theDelay) stop and start the timer? How does this behave? For example does it add on time as I intend to do with my custom library or does it work another way?
https://play.google.com/store/apps/developer?id=Into-It+Games
http://appstore.com/LidiaMaximova