i use the following method do attach or detach some boxes at my node:
public void updateBoxesDrawing(CP_Controller controller) {
if (drawBoxes == true) {
for (int i = 0; i < childList.size(); i++) {
boxNode.attachChild(childList.get(i));
}
boxNode.updateRenderState();
controller.updateRootNode();
}
else if (drawBoxes == false) {
childList = boxNode.getChildren();
boxNode.detachAllChildren();
boxNode.updateRenderState();
controller.updateRootNode();
}
}
childlist is a private ArrayList which is created as class variable. if i first call the method with false then it works. but if i call the method after that with true then childList is always empty. why that?
public void updateBoxesDrawing(CP_Controller controller) {
if (drawBoxes == true) {
for (int i = 0; i < getChilds().getQuantity(); i++) {
boxNode.attachChild(getChilds().getChild(i));
}
controller.updateRootNode();
}
public void storeChilds() {
childList = boxNode.getChildren();
for (int i = 0; i < childList.size(); i++) {
bufferNode.attachChild(childList.get(i));
}
}
public Node getChilds() {
return bufferNode;
}
i works but something strange happens. only every second node is contained in the bufferNode. why that?
childList = boxNode.getChildern;
then in the childList array it is safed.
then i detachAllChildern, but the spatial should be saved in the childList or is there only a reference?
nothing is saved or copied here,
childList is still a reference to the childList in the node.
but i have a second question. how can i really destroy an object like a box? if i just detach it from the node its not drawn but it is still there, how do i really delete a object? (is it clearBatches?)
I had the same problem getting only half of the objects with "getChildren()" in here http://www.jmonkeyengine.com/jmeforum/index.php?topic=9377
[...]
You must do something like that to get *all* children:
ArrayList<Spatial> childList = new ArrayList<Spatial>();
childList.addAll(boxNode.getChildren());
I just couldn't leave that uncommented because it may lead others to false assumptions.
owaye, you profoundly misunderstood what your problem was in the thread you linked.
I won't explain this any further here for it's off topic for this thread, so if you want to know more, please use the other thread to ask.
The important thing to note is: Node.getChildren() returns a REFERENCE to the node's children list, which contains ALL of the Node's children.