Player Hit Quad -> change it

Hi,



I have got a player.getPlayerHits() function which gets me the current player hits! Now I want to make an output health quad (for testing)!



If the health is below 100 the quad should have a width of 300 , if the health is >100 && < 200 the quad should not be seen…


private void checkCollision(float tpf, Enemy enemy){
      
      if(player.getWorldBound().intersects(enemy.getWorldBound())){
         //changeLifeStatus(Int lifes);
         //player.setVelocity(-1f);
         
      player.playerHit();
      
      if (player.getPlayerHits() < 100){
         //3
         
         Node healthNode = new Node("healthNode");
          Quad healthQuad = new Quad("health", 300, 64f);
           healthQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO); 
          
           healthQuad.setLocalTranslation(new Vector3f(DisplaySystem.getDisplaySystem().getWidth()/2,DisplaySystem.getDisplaySystem().getHeight()/2,0));
          
           healthQuad.setLightCombineMode(LightState.OFF);
           healthQuad.updateRenderState();
          
           healthNode.attachChild(healthQuad);
          healthNode.updateRenderState();
         rootNode.attachChild(healthNode);  
      }
      if (player.getPlayerHits() > 100 && player.getPlayerHits() < 200){
         //3
         
         rootNode.detachChild(healthNode);
      }
      
      }
      
   }



How can I make the quad invisible? or is it possible to delete the whole Node?

Several ways to make it invisible:


healthNode.removeFromParent();
healthNode.setCullHint(CullHint.Always);
healthNode.setRenderQueueMode(Renderer.QUEUE_SKIP);



those should all make it not rendered.

I tried that but I get a NullPointerException saying:


03.06.2009 18:24:49 core.SDExceptionHandler uncaughtException
SCHWERWIEGEND: caucht uncaught exception, quitting game
03.06.2009 18:24:49 core.SDExceptionHandler uncaughtException
SCHWERWIEGEND: null
java.lang.NullPointerException
   at gamestates.InGameState.checkCollision(InGameState.java:1363)
   at gamestates.InGameState.update(InGameState.java:335)
   at com.jmex.game.state.GameStateNode.update(GameStateNode.java:71)
   at com.jmex.game.StandardGame.update(StandardGame.java:323)
   at com.jmex.game.StandardGame.run(StandardGame.java:198)
   at java.lang.Thread.run(Thread.java:619)

Post the update method of the InGameState please?

 @Override
    public final void update(float tpf) {
       if (Game.getInstance().isPaused()) {
          tpf = 0;
       }
   
        input.update(tpf);
        chaser.update(tpf);
        updateWater(tpf);
       
        skybox.getLocalTranslation().set( cam.getLocation() );
   skybox.updateGeometricState( 0.0f, true );
      
      
      
     //We don't want the chase camera to go below the world, so always keep
        //it 2 units above the level.
        if(cam.getLocation().y < (terrain.getHeight(cam.getLocation())+2)) {
            cam.getLocation().y = terrain.getHeight(cam.getLocation()) + 2;
            cam.update();
        }
       

       
        //Now we have to make the enemy catch the player if he is in a radius
       catchPlayer(tpf, enemy1);
       catchPlayer(tpf, enemy4);

       checkCollision(tpf, enemy1);
       checkCollision(tpf, enemy4);

       

       
       
        System.out.println("GetHits:" + player.getPlayerHits());
        
           
        rootNode.updateGeometricState(tpf, true);
       
    }
   

I'm guessing enemy4 or enemy1 is null.  Maybe try wrapping it in a null check:



if (enemy1 != null) {

checkCollision(tpf, enemy1);

}

I figured it out! I had to initialize the quad and the node in the initGame! Did that in the update-method! Now it is working nicely! Thanks :wink: