如何在java中使用pygame.time.Clock.tick()?
在python的pygame模块中,我们可以使用:
pygame.time.Clock.tick(90)
来限制游戏中的FPS,但它只适用于python,那么java呢?
我尝试使用:
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)));
}
但每次 FPS 都不一样:
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
java 中是否有 pygame.time.Clock.tick() 的解决方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论