Before the main loop, have
CODE
// Get current time
timeStep = System.currentTimeMillis();
And then do your stuff.
Then before the loop goes back to start, have
CODE
// Hold to lock at FPS
while(System.currentTimeMillis()-timeStep < 1000/60);
Where 60 is the frames per second to run.
This method also allows you to get the difference in times after the while loop in order to find out how much time it took to render one frame. Using this, you could have a variable that you can multiply all your increments by to get frame-independent speed.
For example, if you divide the number of milliseconds it took to handle the frame by 16.666, the number will equal 1 when the program runs at about 60 FPS. When the frame rate is lower, it takes more milliseconds to render the frame and that factor gets bigger.
Be sure to put it BEFORE repaint however. This is the way video games are timed also. An example is shown in my video game base applet code snippet under JAVA.
This post has been edited by WolfCoder: 14 Feb, 2007 - 02:12 PM