FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   delay better than framerate()
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: delay better than framerate()  (Read 518 times)
Andre_Michelle

WWW
delay better than framerate()
« on: Jul 30th, 2004, 1:35pm »

I found this solution to avoid the bucking when using framerate();
 
Code:

int ms;
int defMsPerFrame = 25;
 
void loop()
{
 ms = millis();
 
 {all the drawing, computing code here}
 
 int frameTime = ( millis() - ms );
 int rest = defMsPerFrame - frameTime;
 
 if ( rest > 0 )
 {
  //-- DELAY UNTILL ELAPSE
  delay( rest );
 }
 else
 {
  //println( "computer too slow: " + rest + "  millisecond for this frame: " + frameTime );
 }
}

 
It runs very smooth now in my project.
Maybe it helps anyone.
 
fjen

WWW
Re: delay better than framerate()
« Reply #1 on: Jul 31st, 2004, 10:20am »

i'm not sure how delay is implemented in java, but if it's a timer or an object.wait thing (looks like) than the delay might not be exact .. just a thought. not sure if it matters in this case anyway ..
 
from the java doc:
This class (Timer) does not offer real-time guarantees: it schedules  tasks using the Object.wait(long) method.
&&
from Object.wait(long): (will be awakened if: ) The specified amount of real time has elapsed, more or less.
« Last Edit: Jul 31st, 2004, 10:21am by fjen »  
KQ


Re: delay better than framerate()
« Reply #2 on: Aug 18th, 2004, 4:36pm »

thanks very much. solved my problems
 
fry


WWW
Re: delay better than framerate()
« Reply #3 on: Sep 2nd, 2004, 8:21pm »

that's awfully odd.. since framerate() just calls delay() internally..
 
Pages: 1 

« Previous topic | Next topic »