StatisticsGameState at the end of GameState queue

Currently to use StatisticsGameState you have to extend it. It would be cool to just add an instance of it at the end of the GameState queue instead.

The problem is that statistics text is set in update() method, which is called before render() so renderer statistics is empty. Also currently the statistical information lags one frame behind.

I've mushed StatisticsGameState with TextGameState together to make StatisicsGameState that works at the end of the state queue. There is really no new code, just recombination of what was there. Hope it's useful.

import com.jme.image.Texture;
import com.jme.scene.Node;
import com.jme.scene.Text;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.Timer;

public class StatisticsGameState extends BasicGameState {
   private static final String FONT_LOCATION = "/com/jme/app/defaultfont.tga";
   private Text textObject;
   private Node textNode;

   private Timer timer;

   public StatisticsGameState() {
      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();
   public void update(float tpf) {
   public void render(float tpf) {
      String text = "FPS: " + Math.round(timer.getFrameRate()) + " - " +
   public void cleanup() {

…back when I wrote StatisticsGameState it worked stand-alone…I haven't delved into any jME code for a while (too busy with other projects ATM), but I'm curious what has changed?

The StandartGame.render() method erases previous statistics. My guess is the render method wasn't doing that when StatisticsGameState was first developed.