Failed Counter Code

Put your problem here if it does not fit any of the other categories.

Failed Counter Code

Postby johnsearle » Wed Oct 10, 2012 5:57 am

I'm attempting to write a simple test app that counts down by the second and displays it on the screen. I have used the following to get my current results:

Code: Select all
      Time currentTime = new Time();
      currentTime.setToNow();
      
      int milliDiff = (int) (currentTime.toMillis(false) - startTime.toMillis(false));
      
      if(milliDiff > 1000) {
         startTime.setToNow();
         sec--; // in class scope to count # seconds
         millis = milliDiff;
         
         if(sec < 0) {
            sec = 0;
         } else if (sec < 10) {
            Assets.tick.play(100);
         }               
         
      }



The display code is elsewhere, and the FPS < 1 second. If I set the value of milliDiff to 500, then it seems to run at close to the proper speed.

I know there are other approaches to this problem, but can anyone explain why this fails?

Thanks.
johnsearle
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Oct 10, 2012 5:49 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 15 guests