Package engine

Source Code of engine.FPSCounter

package engine;

import java.awt.Color;
import java.awt.Font;

import com.threed.jpct.FrameBuffer;

import font.GLFont;

public class FPSCounter {
  private Timer timer;
 
  private int totalFps;
  private int lastFps;
  private int fps;
 
  private GLFont font;
 
  private final int REFRESH_TIME_IN_MILISECONDS = 1000;
 
  public FPSCounter(){
    totalFps = 0;
      fps = 0;
      lastFps = 0;
   
    font = new GLFont(new Font("Arial", Font.PLAIN, 16));
    timer = new Timer(REFRESH_TIME_IN_MILISECONDS);
    timer.start();
  }
 
  public void addFrame(){
    fps++;
    if(timer.getElapsedTicks()>0) {
            totalFps = (fps - lastFps);
            lastFps = fps;
        }
  }
 
  public void draw(FrameBuffer buffer, int x, int y){
    font.blitString(buffer, "FPS: " + totalFps, x, y, 100, Color.WHITE);
  }
}
TOP

Related Classes of engine.FPSCounter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.