How to create Energy/Lives that regen in realtime on mobile devices?
I want to create one of those systems on an android device where, losing a level takes away one life point, but you have to wait, say an hour, to get another life point, and you can't play if you have no lives.
The idea I've thought of is to, when the player opens the level select, check the time difference from the last time they opened the level select, and then calculate how much time has passed and go from there, dividing the time by the length, refilling, etc.
Although this seems simple and easy, is there any other ways to do this?
EDIT: To be more clear on what it is I am trying to do, I want an energy system similar to Dots, CandyCrush, BestFiends and other similar games.
Every 15 minutes the player will regen one more energy point. There is a timer visible in the UI ticking down til their next regain. If they were to close the app for two minutes, then return, two minutes should have passed on the in game timer as well. And if they are gone for an hour, when they come back, they will have four energy points and the timer is again counting down to the next regain point.
The timer has to appear to be constantly ticking when the app is not running, so they can always open it up and see that every second that has passed in the real world as passed in the game.
I would probably store a list of active start times for each timer and then you can find out where their appropriate end time should be by adding to start time and comparing that against the current time. If the timer still needs to run then you can update it in tick as it counts down towards the end time.
Follow this question
Once you sign in you will be able to subscribe for any updates here