Package org.pollux3d.state

Source Code of org.pollux3d.state.FramesPerSecondState

package org.pollux3d.state;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.math.FastMath;
//import com.jme3.renderer.Camera;
import com.jme3.scene.Node;

public class FramesPerSecondState extends AbstractAppState {
 
  private Node fpsNode = new Node("FramesPerSecondNode");
  private AssetManager assetManager;
  private BitmapFont guiFont;
  private BitmapText fpsText;
  //private BitmapText camText;
  private boolean isHigh = false;
  private static int high = 150;
  //private Camera cam;
 
  public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    //cam = app.getCamera();
    assetManager = app.getAssetManager();
        guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
        fpsText = new BitmapText(guiFont, false);
        fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0);
        fpsText.setText("Frames per second");
        //camText = new BitmapText(guiFont, false);
        //camText.setLocalTranslation(0, camText.getLineHeight()*5, 0);
        //camText.setText("Cam: ");
       
        fpsNode.attachChild(fpsText);
        //fpsNode.attachChild(camText);
  }

  /* (non-Javadoc)
   * @see com.jme3.app.state.AbstractAppState#update(float)
   */
  @Override
  public void update(float tpf) {
    int fps = (int) FastMath.ceil(1/tpf);
    if (fps > high) {
      if (!isHigh) {
        fpsText.setText("Frames per second: "+high+"+");
        isHigh = true;
      }
    } else {
      isHigh = false;
      fpsText.setText("Frames per second: " + fps);
    }
    //camText.setText("Cam: "+cam.getLocation().toString());
  }
 
  public Node getFPSNode() {
    return fpsNode;
  }
 

}
TOP

Related Classes of org.pollux3d.state.FramesPerSecondState

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.