Node.removeFromParent() effect

Actually I would like to remove a node from the scene, in particular a DynamicPhysicsNode.

If this node is attached to the root Node and I call the method removeFromParent(), will I no longer see it in scene or not ?

Yes, after calling removeFromParent the node and all it's children are no longer visible and are not updated any more. For a PhysicsNode make sure you also call setActive(false) to remove it's physical representation.

Well the hints for DynamicPhysicsNode solved, but…



in a cycle like this :


display.getRenderer().draw (node);
display.getRenderer().renderQueue():



calling, in an object inside the node in draw method:



public void draw () {
  ...
  this.removeFromParent()
   ...
}



it causes this :


Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
   at java.util.ArrayList.RangeCheck(Unknown Source)
   at java.util.ArrayList.get(Unknown Source)
   at com.jme.scene.Node.draw(Node.java:509)
   at com.jme.scene.Spatial.onDraw(Spatial.java:210)
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:1124)



It seems to me that when renderer goes to render the queue it does not find all the nodes, it's possible ?

Make sure you're removing that in the update thread, not in a separate one or this will happen.



If you're using StandardGame you can safely use the game.lock() / unlock() features to accomplish this in another thread.

He does not use threads. The draw methods should do nothing more than drawing. You should alter the scenegraph only while not rendering.

I solved whi this :


package it.phoenix.scene;

import com.jme.scene.Node;
import com.jme.scene.SceneElement;
import com.jme.scene.Spatial;

public class TimedNode extends Node {

   private int times         = 1000;
   private int timesElapsed   = 0;
   
   public TimedNode (Spatial child, int times){
      this.attachChild(child);
      this.setTimes(times);
   }
   
   public void setTimes (int times){
      this.times = times;
   }
   
   public void update (){
      
   }
   
   public void updateGeometricState(float time, boolean initiator) {
      if (timesElapsed == times){
         this.removeFromParent();
         return;
      }
      timesElapsed++;
    }
}



One size fits all (I don't know an english slogan for the event, but it sounds good).