topical media & game development

talk show tell print

graphic-processing-learning-10-example-10-9-Timer.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 10-5: Object-oriented timer
  
  class Timer {
   
    int savedTime; // When Timer started
    int totalTime; // How long Timer should last
    
    Timer(int tempTotalTime) {
      totalTime = tempTotalTime;
    }
    
    // Starting the timer
    void start() {
      // When the timer starts it stores the current time in milliseconds.
      savedTime = millis(); 
    }
    
    // The function isFinished() returns true if 5,000 ms have passed. 
    // The work of the timer is farmed out to this method.
    boolean isFinished() { 
      // Check how much time has passed
      int passedTime = millis()- savedTime;
      if (passedTime > totalTime) {
        return true;
      } else {
        return false;
      }
    }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.