问题描述:

I'm working on a game, and I normally use Fraps to record video. While I was developing and testing, I noticed that the FPS counter was being cut off. Here's a pic:

http://i.stack.imgur.com/YvEH9.png

http://i.stack.imgur.com/z7NKL.png

(I can't post an image, I need more reputation xD)

Any ideas?

Help is appreciated!

网友答案:

This is hard to solve, because it is a problem with Fraps instead of your application. I would add your own system to find the FPS within your application. This is the FPS counter I used for one of my recent projects in java: (This caps the FPS and also calculates it.)

public static final double MAX_FPS = 60;
@Override
public void run() {
    long lastTime = System.nanoTime();
    double nsPerTick = 1000000000D/MAX_FPS;

    int ticks = 0; //Every time it runs the game

    long lastTimer = System.currentTimeMillis();
    double delta = 0;
    init();
    //Game loop

    while (true){
        long now = System.nanoTime();
        delta += (now - lastTime) / nsPerTick;
        lastTime = now;
        boolean shouldRender = true;
        while(delta >= 1){
            ticks++;
            update();
            delta-=1;
            shouldRender = true;
        }

        try {
            Thread.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (shouldRender){

            draw();
            drawToScreen();
            }

            if (System.currentTimeMillis() - lastTimer >= 1000){
                lastTimer += 1000;
                fps = ticks;
                ticks = 0;
            }
    }
}
相关阅读:
Top