Virtual Pet Games on iPhone

I plan to make a virtual game with my favorite games with different timers in the game (how often hunger occurs, as well as an energy system in which there are many games for facebook).

However, I think that if the user closes the application, we will not be able to access the application timer correctly? So it is necessary that the server is accessible in another, so that the application runs smoothly.

One of the solutions I was thinking about was using [NSDate date] , is this possible?

Thanks.

0
source share
4 answers

The best way is to save important events and use the timer in the game strictly to check the next event. For example, if the owner is feeding the dog, simply write that the dog was feeding at this real time, and then each time fired a timer to check if enough time had passed to make the dog starve again. Thus, the actual state of the timer does not matter.

In addition, this means that you do not need more than one timer. You will have a handler method that will look at your state and run other methods as necessary depending on the amount of time since the last event.

+2
source

If your pet game requires the user to be in the application for playback, you can always save the necessary data and reload it when the user starts the application again. Otherwise, you probably need a server and synchronize every time.

0
source

Computers are very fast these days.

Entire statistics for the day can be generated indiscriminately, even without the use of discrete formulas - if the application is not open, then the pet does not need to "become hungry" and any changes in statistics or "daily events" can be generated as soon as the application is active again - No need to even worry about background events for an inactive application.

However, I suspect that for a more friendly game, additional β€œsoft” logic will be used to encourage the user to play with the pet without having to starve to death during a business meeting: this is a game and games can create their own rules while the user continues to play.

Happy coding.

0
source

It seems to me that your question is related to how to make your timers light up, even when the application is closed. The answer is that you are not doing this. However, you can use local storage on the iPhone to store the most recent time, when the XYZ event occurred, and when the application starts up again (say, after 1 day), you can compare the current time with the most recently saved time and quickly update the status before the user sees something otherwise. The user will not be wiser, and he will look as if time had really expired in the game world.

0
source

All Articles