Print Timer on Screen

Hi everyone,

I am trying to print the Timer.getTimer().getTimeInSeconds() value on my screen of my game!

I tried to use the Font3D example for my needs! I added the Timer.getTimer().getTimeInSeconds() into createText!

Font3D font = new Font3D(new Font("Arial", Font.PLAIN, 24), 0.001f, true, true, true);
            Text3D text = font.createText("" + Timer.getTimer().getTimeInSeconds(), 50.0f, 0);
            text.setLocalScale(new Vector3f(5.0f, 5.0f, 0.01f));

After starting my game I figured that this is not the right way to do it!

Does anybody know a working way to do it?

Thanks for any help ;)
  1. dont do it with Text3D, you should only use that for static text, if you create a 3d text every update cycle you wont have any FPS  :wink:
  2. take a look at DebugGameState if you use StandardGame, or look at any of the tests in the jme 2.0 source, in those you can toggle a statistik view with many values (incl. FPS)
  3. if you still want to do it on your own:

   public void init(StandardGame game) {
      // Then our font Text object.
      // This is what will actually have the text at the bottom.
      fps = Text.createDefaultTextLabel("FPS label");

      // Finally, a stand alone node (not attached to root on purpose)
      fpsNode = new Node("FPS node");
      fpsNode.updateGeometricState(0.0f, true);
   } // init

   public void update(float tpf) {
      // print the FPS information
      StringBuffer updateBuffer = new StringBuffer();
      updateBuffer.append("FPS: ").append(Math.round(1 / tpf));
      /* Send the fps to our fps bar at the bottom. */
   } // update

   public void render(float tpf) {
   } // render

I am using an InGameState  which extends PysicsGameState!

Which means you are using StandardGame. Create and add a StatisticsGameState.

okay thanks :wink:

One more thing:

I looked at StatisticsGameState and tried to integrate the function to my GameState!

So I have a initStatistics() in my initGame-function:

private void initStatistics(){
      AlphaState as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
      TextureState font = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
                  Texture.MM_LINEAR, Texture.FM_LINEAR));
      textObject = new Text("Text", "");
      textNode = new Node("TextNode");
      textNode.updateGeometricState(0.0f, true);
      timer = Timer.getTimer();

and then I changed my render-method:

    public void render(float tpf) {
       if (Game.getInstance().isPaused()) {
          tpf = 0;
       String text = "FPS: " + Math.round(timer.getFrameRate()) + " - " +

When I start my game no error appears! But I can't see anything!?!  Any ideas?

Did you turn off lighting for the text object? (Spatial.LightCombineMode property)



It did not solve the problem ;-(

use Spatial.setCullHint(CullHint.Never) and ZBufferState.setFunction(TestFunction.Always)

also make sure to render the textNode in the ortho queue node.setRenderQueueMode(Renderer.QUEUE_ORTHO);

sorry for being unclear before: you should not integrate the functionality from StatisticsGameState into your GameState. somewhere in your code you should have something like that:


right below it, you can create your StatisticsGameState and add it to the GameStateManager, just like above. Else, you would just screw up the whole point of GameStates  ;)

okay great!

Working really good now- even as an own StatisticsGameState :wink: