Hi!
Make a fun that check how much time you have had the app open…
So that it begins when the player presses “Play” and end when it’s game over… In sec(probably with an interval of 0.5 )
Thanks!!!
Hi!
Make a fun that check how much time you have had the app open…
So that it begins when the player presses “Play” and end when it’s game over… In sec(probably with an interval of 0.5 )
Thanks!!!
Just take a look here.
http://www.cplusplus.com/reference/chrono/duration/duration/
http://www.cplusplus.com/reference/chrono/duration/count/
http://www.cplusplus.com/reference/chrono/time_point/
You could just use the example here:
http://en.cppreference.com/w/cpp/chrono
Oh, and you might want to use std::chrono::steady_clock instead of std::chrono::system_clock to prevent cheating, as it cannot be decreased like the wall clock.
Class std::chrono::steady_clock represents a monotonic clock. The time points of this clock cannot decrease as physical time moves forward. This clock is not related to wall clock time, and is best suitable for measuring intervals.
Are you sure about this ? i’ve tried every single way to obtain time that is not tied to clock on Android and iOS without any success.
With which compiler does this happen?
VC has a bug, and it’s steady clock is not steady.
Just tested it with VS Community Edition 2013, and steady clock ends in a - value, if you set the system clock back.
Despite printing out “yes”
CCLOG("clock::is_steady: %s\n", std::chrono::steady_clock::is_steady ? "yes" : "no");
it’s not steady on different compilers. You would need to test it.
Totally, and here is my proof. You can alter your time, but it will never decrease.
std::chrono::steady_clock::time_point start, end;
start = std::chrono::steady_clock::now();
CCLOG("I love my C64!");
end = std::chrono::steady_clock::now()
std::chrono::duration<double> elapsed_seconds = end - start;
CCLOG("It just took me %f seconds to tell you that!", elapsed_seconds.count());
Output:
I love my C64!
It just took me 0.001000 seconds to tell you that!
That is NOT tied to clock? Time is always tied to a clock, but it can be tied to the system clock/wall clock or the monotonic clock. Are you referring to the system clock?
Post your code.
You could also use the total frame count from Director for a rough estimation (not considering lag etc.) if precision isn’t that important:
auto timeSinceAppStart = Director::getInstance()->getTotalFrames() * Director::getInstance()->getAnimationInterval();
That could be another solution.
If you want to fight cheating, I suggest getting the time from a trusted time server.
At the end i’ve implemented a quick network request to get time from sntp pool server and prevent cheating by changing time on system, this is the most clean way, only downside is that it requires internet connection. But i remember when i was testing that every single way of getting time was influenced by current device time.