New answers tagged timer
Basically, your Log statement is taking up a few milliseconds, so what your code is actually doing looks sorta like this from a time perspective: |---------1 sec------|-Log-|---------1 sec------| As Mr. Beast said, you should use time += 1000000000;, not time = System.nanoTime();
I find it easiest to keep a delta time per frame updated in the onDrawFrame() of my surface view's renderer. This way it always reflects only the time that has elapsed since my last draw call, and I can accumulate this value as needed for delays and timing. The following is a quick example of how I usually implement this: public class GameRenderer ...
You can always implement a clock by yourself which is updated together with the real time clock. If you implement your own clock, you can even scale it for a slow-motion effect, or speed it up, as seen in many tower defense games. Update: Okay, you may want to consider using a set of 3 variables to keep track of time: current time (now) previous time ...
Top 50 recent answers are included