java – 制作FPS淋浴?
作者:互联网
我试图用FPS显示一个字符串,但是,我如何实际获得我的程序FPS?我想这样做
g.drawString(getFPS(), 10, 10)
我如何获得我的FPS?
解决方法:
这段代码适合我.把它放在主程序循环中:
//To Measure FPS
private long now;
private int framesCount = 0;
private int framesCountAvg=0;
private long framesTimer=0;
//Main Game Loop
while (isRunning)
{
//Record the time before update and draw
long beforeTime = System.nanoTime();
//... Update program & draw program...
// DRAW FPS:
now=System.currentTimeMillis();
gEngine.drawFPS(c, framesCountAvg);
framesCount++;
if(now-framesTimer>1000)
{
framesTimer=now;
framesCountAvg=framesCount;
framesCount=0;
}}
调用“gEngine.drawFPS”只是告诉我的主要绘制方法将fps包含在屏幕顶部(而c是我的Canvas) – 你可以使用类似的方法为你的“g”类提供正确的framesCountAvg数据来绘制
标签:frame-rate,java 来源: https://codeday.me/bug/20191008/1871344.html