i’m trying to make some sort of Business Simulation Game and everything is working just fine for most of the tasks i’ve planned to develop..
now i have to think about how to implement the time management in the game logic, in order to change state to sprites or assign bonuses, coins, .. depending on time.
but most of all, how to do that while the application isn’t running (ie. when it re-run..)
i think i should use some sort of gameloop checking for time events, i’ve searched the web but i didn’t find any useful information.. mostly about how to syncronize time event on re-run
..the only solution i could think about is to rely on a Date object, but what if the user then change it’s device’ system date or simply travel to another time zone?
If your users find out that your app is running in the background when they didn’t tell it to, even for a few seconds, you’re going to make people angry. I would recommend strongly against that.
Instead, when your game starts up after a period of inactivity, whether it be five minutes or five months, check the time difference since the last run, and run your simulation at maximum speed until you’re up to date. Maybe show them a progress bar if it’s been a long time.
Also, don’t worry about people changing the time on their phone. If they want to play your game enough to mess with that, well, that’s kind of flattering, isn’t it? Time zones shouldn’t matter, because you should be processing all of your data based on machine time and not local time. Just make sure you handle the edge case where someone sets their clock back, and you find that they have not played your game in -1 hour.