Answer the question
In order to leave comments, you need to log in
How to make the clicker work in the background?
Hello, for many clickers, when you upgrade automatic currency generation, close the application and then go in, then a window pops up like "You have accumulated 50,000 currencies while you were away", please tell me how to do this so that while my application is closed, then currency would accumulate further>?
Answer the question
In order to leave comments, you need to log in
In full-fledged clickers and other games where the gameplay is used in a "non-working" state - either the mechanics work on the server (which is rarely done, only in cases of possible influence of other players from the outside), or they carry out an accelerated simulation.
For example, there is some building that accumulates gold over time in a time according to the formula
сurrency(t) = t*currencyPerSecond
where t is time, and currencyPerSecond is the amount of currency accrued in seconds.
As a result, the player sits and plays, receives currencyPerSecond every second . And here we have to save somewhere the moment at which we last received this currency. For example, at 11:00 the player received currencyPerSecond and now he has 10000 gold. We recorded this and saved it to a save file, some json or something like that.
The player closed the game and opened it in half an hour, at 11:30 .
We went to see when the player last received the currency - at 11:00 , and now it's 11:30 - so he was absent for 30 minutes and we have to generate him
30*60*currencyPerSecond (30 минут * 60 секунд * на величину получаемого золота в секунду)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question