I have been searching the web and seen different ways of making fps limitations but i cannot quite find the best way to do it and an explanation following with it.
Could someone please tell me how to make an fps limiter and explain how it works?
I did create a game before using LWJGL but it synced the fps for me
My current code:
public void run(){
long beforeTime, timeDiff, sleepTime;
int period;
period = 1000/60;
beforeTime = System.currentTimeMillis();
while(Running == true){
Update();
Draw();
timeDiff = System.currentTimeMillis() - beforeTime;
sleepTime = period - timeDiff;
if(sleepTime <= 0)
sleepTime = 5;
try{
Thread.sleep(sleepTime);
}
catch(InterruptedException ex){}
beforeTime = System.currentTimeMillis();
}
}