Resume timer

Monkey Targets Forums/iOS/Resume timer

soXes(Posted 2013) [#1]
Hi all,

I created a label to display game duration. I have created its timer by calling CreateTimer.

lblTime = eng.CreateText(font, "1:05:12", px, py)
lblTime.SetLayer(bgLayer)
lblTime.SetScale(0.5)
lblTime.CreateTimer(TIMER_TAG, 1000, -1)

The issue is when i resume game from background, timer can not continue running. in OnResume method, i set lblTime.ResumeTimerAll() but it is not work

please give me advice


MikeHart(Posted 2013) [#2]
soXes,

these seem to be fantomEngine related questions. For the future, please somehow mention fanotmEngine in your message. Better: Prefix the title of your post.This way I have a chance to find them. Or even better, post them in my dedicated support forum.

Which version of fE are you using? How do you stop the engine/timer?


soXes(Posted 2013) [#3]
thanks for your advice,

i am using fE version 152, i call method PauseTimerAll on OnSuspended


soXes(Posted 2013) [#4]
The problem is when i call start game method in OnObjectTouch of engine. In StartGame method i created a timer for lblTime. But timer work well when i call StartGame in OnUpdate method of App. Do you have any advice?


MikeHart(Posted 2013) [#5]
First off all, if you want to pause the engine, I woudl use

yourEngine.SetPaused(True)

inside the OnSuspend method.


Second, can you post a sample script that illustrates this small problem. It is difficult to analyse your problem without the code.


soXes(Posted 2013) [#6]
If i call CreateTimer here at callback OnObjectTouch of engine. Timer is only fired only 1 times.
Method OnObjectTouch:Int(obj:ftObject, touchId:Int)
Select obj.GetTag()
Case g.menu.START_BUTTON_TAG
lblTime.CreateTimer(TIMER_TAG, 1000)

End

In case i call it on OnUpdate, it runs well:
Method OnUpdate:Int()
If isSuspended = False Then
Local d:Float = Float(eng.CalcDeltaTime())/60.0
Select gameMode
Case gmPlay
lblTime.CreateTimer(TIMER_TAG, 1000)
End
Endif
Return 0

End

What is the difference here?

When we create timer with loop = -1, we can not stop it right? because i removed all timer on object but OnObjectTimer method still called.


MikeHart(Posted 2013) [#7]
So far i had no probs with timers. Like i said, please create a small example that shows the problem lnd send it to contact (at) michaelhartlef.de so i can look at it.

In your code above both timers are not repeating themself because of the default loop parameter.