Overlay 2 Gamestates

Hi everyone,



I am working with 3 GameStates. InGameState, HUDGameState and StatisticsGameState!



I want my Statistics to be on top of the HUDGameState! At the moment it is the other way arround!


public HUDGameState(final String name) {
      super(name);
      
      hudNode = new Node("hudNode");
       Quad hudQuad = new Quad("hud", 1024f, 64f);
        hudQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO);       

        hudQuad.setLocalTranslation(new Vector3f(DisplaySystem.getDisplaySystem().getWidth()/2,DisplaySystem.getDisplaySystem().getHeight()- 64,0));
       
        hudQuad.setLightCombineMode(LightState.OFF);
        hudQuad.updateRenderState();

       

       // create the texture state to handle the texture
          final TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
          // load the image bs a texture (the image should be placed in the same directory bs this class)
          URL texture2=Start.class.getClassLoader().getResource(
          "data/images/topleiste.png");
          final Texture texture = TextureManager.loadTexture(texture2,
                  Texture.MM_LINEAR_LINEAR , // of no use for the quad
                  Texture.FM_LINEAR , // of no use for the quad
                  1.0f,
                  true);
          // set the texture for this texture state
          ts.setTexture(texture);
          // initialize texture width
           textureWidth = ts.getTexture().getImage().getWidth();
          // initialize texture height
          textureHeight = ts.getTexture().getImage().getHeight();
          // activate the texture state
          ts.setEnabled(true);
         
          final FloatBuffer texCoords = BufferUtils.createVector2Buffer(4);
          // coordinate (0,0) for vertex 0
          texCoords.put(getUForPixel(0)).put(getVForPixel(0));
          // coordinate (0,40) for vertex 1
          texCoords.put(getUForPixel(0)).put(getVForPixel(1024));
          // coordinate (40,40) for vertex 2
          texCoords.put(getUForPixel(64)).put(getVForPixel(1024));
          // coordinate (40,0) for vertex 3
          texCoords.put(getUForPixel(64)).put(getVForPixel(0));
          // assign texture coordinates to the quad
          hudQuad.setTextureBuffer(0,texCoords,0);
          // apply the texture state to the quad
          hudQuad.setRenderState(ts);
         
       // to handle texture transparency:
          // create a blend state
          final AlphaState bs = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
          // activate blending
          bs.setBlendEnabled(true);
          // set the source function
          bs.setSrcFunction(AlphaState.SB_SRC_ALPHA);
          // set the destination function
          bs.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
          // set the blend equation between source and destination
        //  bs.setBlendEquation(AlphaState. BlendEquation.Subtract);
          bs.setTestEnabled(false);
          // activate the blend state
          bs.setEnabled(true);
          // assign the blender state to the quad
          hudQuad.setRenderState(bs);
   
          hudNode.attachChild(hudQuad);
          hudNode.updateRenderState();
          rootNode.attachChild(hudNode);
           
   }



public StatisticsGameState(final String name) {
      super(name);

      
      AlphaState as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
      as.setBlendEnabled(true);
      as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
      as.setDstFunction(AlphaState.DB_ONE);
      as.setTestEnabled(true);
      as.setTestFunction(AlphaState.TF_GREATER);
      as.setEnabled(true);
      
      TextureState font = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      font.setTexture(TextureManager.loadTexture(StandardGame.class.getResource(FONT_LOCATION),
                  Texture.MM_LINEAR, Texture.FM_LINEAR));
      font.setEnabled(true);
      
      textObject = new Text("Text", "");
      textObject.setTextureCombineMode(TextureState.REPLACE);
      textObject.setLocalTranslation(50,700, 0);
      textObject.setLocalScale(3f);
      textNode = new Node("TextNode");
      textNode.attachChild(textObject);
      textNode.setRenderState(font);
      textNode.setRenderState(as);
      textNode.updateGeometricState(0.0f, true);
      textNode.updateRenderState();
      
      timer = Timer.getTimer();
      DisplaySystem.getDisplaySystem().getRenderer().enableStatistics(true);
      textObject.print("Pending...");
   }



What do I have to change to print the statistics on top of the hud?
Thanks

Add the StatisticsGameState to the GameStateManager last.

working! Should have thought about that too :wink: Thanks

np. just remember that the render and update methods are called in order of the game states registered and it's easy to remember.