rootNote "static" problem

Hi everyone,



I want "restart" to my Game without having to load everything newly! So I created this function:



public static void rebuildGame(){

       Timer.getTimer().reset();
       StatisticsGameState.setTimer(null);
       
       player.setAcceleration(50);
        player.setTurnSpeed(4.5f);
        player.setMaxSpeed(60);
        player.setMinSpeed(0);
        player.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
        player.setLocalTranslation(new Vector3f(378,2,287 ));
       
      
        rootNode.detachChild(fishNode);
       
    }



--> calling it in another State...


InGameState.rebuildGame();
GameStateManager.getInstance().activateChildNamed("InGame"); 



So the player is set to his "start" position! Now I want to do this with the fish too! I want to detach them and then build them newly (because there are several of them)...

I get the error saying, that the rootNode can't be used for static! When I change it in jme to be static the function works, but the screen is black!

Is there a way to do this?

Thanks...

a dirty flag in renderstate in badly needed…

So you want to keep the player but rebuild your fishes?

You could detach all nodes from the rootNode ( detachAllChildren() ), attach your old player to it and then attach your new fishes.



It would be probably nicer, when you create a sub-node under the rootNode, where you attach all elements you want to recreate. So you only have to clean up this node and don

That makes sence and works really good :wink: Only problem is, that the models have a really weird texture…



I detached them and then build them newly:






    public static void rebuildGame(){

       Timer.getTimer().reset();
       
       player.setVelocity(0);
       player.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
        player.setLocalTranslation(new Vector3f(378,2,287 ));
       
        rootNodeCopy.detachChild(crocodileNode);
        rootNodeCopy.detachChild(fishNode);
        rootNodeCopy.detachChild(fishNode2);
       
        buildFish();   //fish
        buildCrocodile(); //crocodiles      
        buildFish2(); // Water_Lilys
    }



for example:


   private static void buildFish(){
      Spatial fish1 = null;

         try {
           
            fish1 = (Spatial)BinaryImporter.getInstance().load(ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "fish.jme"));
            fish1.setLocalScale(1f);
            fish1.setModelBound(new BoundingBox());
            fish1.updateModelBound();

           } catch (Exception e) {
               System.out.println("Damn exceptions! O_o n" + e);
               e.printStackTrace();
               System.exit(0);
           }
          
           fishNode = new Node("fishNode");
           //set the water_lily attributes
           fishModel = new Node("fishModel");
           fish = new Enemy("crocodile", fish1);
           fishModel.attachChild(fish);
             
          fishNode = new Node("fishNode");
            
              //set the fish attributes
          SharedNode fish2 = new SharedNode("fish", fishModel);
          fish2.setLocalTranslation(new Vector3f(180,1.8f,200 ));                
          fishNode.attachChild(fish2);
             
          SharedNode fish3 = new SharedNode("fish", fishModel);
          fish3.setLocalTranslation(new Vector3f(203, 2, -9));                
          fishNode.attachChild(fish3);
             
          SharedNode fish4 = new SharedNode("fish", fishModel);
          fish4.setLocalTranslation(new Vector3f(-3, 2, -270));                
          fishNode.attachChild(fish4);
                  
          SharedNode fish5 = new SharedNode("fish", fishModel);
          fish5.setLocalTranslation(new Vector3f(-121, 2, -110));                
          fishNode.attachChild(fish5);
       
          SharedNode fish6 = new SharedNode("fish", fishModel);
          fish6.setLocalTranslation(new Vector3f(-121, 2, 178));                
          fishNode.attachChild(fish6);

          rootNodeCopy.attachChild(fishNode);       
                   
   }



How can I change the texture to be right again?

Do you call rootNode.updateRenderStates() after rebuilding everything?

works ;)  Thanks so much !!

Is it possible that the question "Have you called updateRenderStates()?" in this forum is as effective as "Have you tried turning it off and on again?" when someone needs help with his PC? :smiley: