In my project, I call nanoTime and use that to get a deltaTime which I pass to my entities and animations.

However, while debugging (for example, stepping through my code), the system time on my phone is happily chugging along, so it's impossible to look at, say, two sequential frames of data in the debugger (since by the time I'm done looking at the first frame, the system time has continued to move ahead by seconds or even minutes).

Is there a programming practice or method to pause the system clock (or a way for my code to intercept and fake my deltaTime) whenever I pause execution from the debugger?

Additional Information:

  • I'm using Eclipse Classic with the ADT plugin and a Samsung SII, coding in Java.
  • My code invoking nanoTime: http://pastebin.com/0ZciyBtN
  • I do all display via a Canvas object (2D sprites and animations).
  • \$\begingroup\$ A friend mentioned manually editing the deltaTime in the debugger before I pass it to the rest of my game in the next frame. If I could detect that the debugger is attached, I could set the deltaTime to an artificial amount each frame if I'm debugging. \$\endgroup\$ Sep 6, 2012 at 0:29

1 Answer 1


Instead of grabbing the system time and calculating the delta time each frame, just keep the delta frame time constant in the debug build (deltaTime is just always 16ms, for example). This way each simulation frame has a fixed time step regardless of how much debugging you did in between frames. Of course this should only be done in your debug build.

  • 1
    \$\begingroup\$ You could modify that technique slightly and say each frame has a maximum delta time (33ms, perhaps). By doing this, you will lose time, but you will never gain time. \$\endgroup\$
    – notlesh
    Sep 6, 2012 at 2:27
  • \$\begingroup\$ Is there a way to make this automatically change in my debug build, as opposed to changing a "global" variable each time I switch between Debug/Run? \$\endgroup\$ Sep 6, 2012 at 9:27
  • \$\begingroup\$ As far as I know Java doesn't have support for conditional build statements (like #ifdef), but then again I'm not a Java developer. You could always ask that on StackOverflow.com and get a real answer. \$\endgroup\$ Sep 6, 2012 at 13:14
  • \$\begingroup\$ This apparently is a real terror... stackoverflow.com/questions/12296762/… \$\endgroup\$ Sep 6, 2012 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .