进行FPS淋浴吗? [英] Making a FPS shower?

查看:52
本文介绍了进行FPS淋浴吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用FPS显示字符串,但是,实际上我该如何使我的程序获得FPS?我想用

I am trying to make a string with FPS showing, but, how do I actually get my programs FPS? I want to do it with

g.drawString(getFPS(), 10, 10)

我如何获得我的FPS?

How do I get my FPS?

推荐答案

此代码对我有用.将其放在您的主程序循环中:

This code does it for me. Put it in your main program loop:

//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绘制数据

that call "gEngine.drawFPS" just tells my main draw method to include the fps at the top of the screen (and c is my Canvas) - you can use a similar method to give your "g" class the correct framesCountAvg data to draw

这篇关于进行FPS淋浴吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆