'How can I use pygame.time.Clock.tick() in java?
In python's pygame module, we can use:
pygame.time.Clock.tick(90)
to limit FPS in game, but it's only works on python, what about java?
I tried to use:
public void paint(Graphics canvas){
long begin_time = System.currentTimeMills();
// do Jframe paint / game loop here
long MSPT = System.currentTimeMills() - begin_time;
if (MSPT < 10){
try {
Thread.sleep(10 - MSPT);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("FPS: " + (1000 / (System.currentTimeMills() - begin_time)));
}
but each time FPS is not same:
Terminal
FPS: 83.33333333333333
FPS: 83.33333333333333
FPS: 76.92307692307692
FPS: 83.33333333333333
FPS: 83.33333333333333
FPS: 76.92307692307692
FPS: 76.92307692307692
FPS: 90.9090909090909
FPS: 76.92307692307692
FPS: 83.33333333333333
FPS: 100.0
FPS: 90.9090909090909
FPS: 100.0
FPS: 83.33333333333333
FPS: 76.92307692307692
FPS: 83.33333333333333
FPS: 100.0
Are there any workaround of pygame.time.Clock.tick() in java?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
