How to make a timer to run if app is suspended
Monkey Forums/Monkey Programming/How to make a timer to run if app is suspended
| ||
For my type of game, I need to continue run a timer (to refill the player energy) even if this one suspended the application from the iPad or Android Hoem button. I am using the small cDeltaTimer class, but the update is done in OnUpdate. How should I handle this? |
| ||
Well, you can check Millisecs() when an update finally occurs, and update the energy then based on the total time elapsed I.e. if the last update was 15 minutes ago, give a full 15 minutes of energy, even if nothing else gets 15 minutes worth of updates. |
| ||
Well, I made this test:Method OnResume:Int() Print "resumed @ " + Millisecs()' End Method OnSuspend:Int() timerSuspended = Millisecs() Print "suspend @ " + timerSuspended End but the Millisescs() is returning the actual app time so when i come back is still the same time as when I leave.. |
| ||
Raul wrote: but the Millisescs() is returning the actual app time so when i come back is still the same time as when I leave.. Calculate time to full refill, store it and check time to up in update loop. |
| ||
@nikoniko: Lets say the time to refill is 60 seconds. When the users suspends the application I store this value, right? Second time when he enters, how do I know how many seconds pasts since last check? |
| ||
GetDate function in mojo.app. Is that what you are looking for? |
| ||
I didn't realise that Millisecs() stopped when the app was suspended. But as Ferdi says, GetDate() is therefore the answer. |
| ||
Yeah! GetDate() Thanks guys :D Love you all! |
| ||
Just a warning in GLFW the millisecs part is not working in GetDate. It works in HTML5. |
| ||
Thanks for sharing that Ferdi, but I only need this for iOS and Android. |