[java] Java 1.1 Time
I wanted to know how I could setup a fps meter in java 1.1.
Basically I was thinking I could use the system clock and then divide by how much the thread repaints itself. Unfortunely I'm not familiar with java and doing things like that.
Edited by - Black Marq on July 17, 2001 6:34:13 PM
System.currentTimeMillis()
Will get you a rough approximation of the number of milliseconds have passed since windows started. So as long as you keep track of how many frames you have painted with a ...
private long frames = 0;
repaint(Graphics g) //or whatever else you are using
{
frames++;
...
}
And when before you start your FIRST frame.
startTime = System.currentTimeMillis();
Then your average fps can be calcualted with...
fps = (double)(1000 * frame) / (double)(System.currentTimeMillis() - startTime;
should give you an approximate fps counter.
Gotchas:
currentTimeMillis() is only accureate to about 50ms under windows, so it is useless for any timing of things over 10-15fps unless averaged against several frames.
Will get you a rough approximation of the number of milliseconds have passed since windows started. So as long as you keep track of how many frames you have painted with a ...
private long frames = 0;
repaint(Graphics g) //or whatever else you are using
{
frames++;
...
}
And when before you start your FIRST frame.
startTime = System.currentTimeMillis();
Then your average fps can be calcualted with...
fps = (double)(1000 * frame) / (double)(System.currentTimeMillis() - startTime;
should give you an approximate fps counter.
Gotchas:
currentTimeMillis() is only accureate to about 50ms under windows, so it is useless for any timing of things over 10-15fps unless averaged against several frames.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement