I want to detach a spatial in my rootNode. I have my button using NiftyGUI.
public class Main extends SimpleApplication{
...
...
Sphere sp = new Sphere(100,150,3f, false, false);
Spatial sphere = new Geometry("Earth", sp);
rootNode.attachChild(sphere);
...
}
...
...
XML
...
interact onClick="removeBox()"
...
What's going to be in my method?
public class GuiController extends AbstractAppState implements ScreenController
public void removeBox() {
????????
}
zarch
March 12, 2013, 10:15pm
2
This is covered in the first few tutorials, especially the scene graph ones…
So I finally figured it out again on my own… HOOORAY!
System.out.println(app.getViewPort());
System.out.println(app.getViewPort().getScenes());
System.out.println(((Node)app.getViewPort().getScenes().get(0)).getChildren());
((Node)app.getViewPort().getScenes().get(0)).detachChildNamed(“Earth”);
@viridia01 said:
So I finally figured it out again on my own... HOOORAY!
System.out.println(app.getViewPort());
System.out.println(app.getViewPort().getScenes());
System.out.println(((Node)app.getViewPort().getScenes().get(0)).getChildren());
((Node)app.getViewPort().getScenes().get(0)).detachChildNamed(“Earth”);
Don’t you need to enqueue this?
[java]
Callable call = new Callable() {
public Object call() throws Exception {
app.getRootNode().detachChildNamed(“Whatever”);
return null;
};
app.enqueue(call);
[/java]
Um… I wrote this from memory (which isn’t always full of… well… memories. But, it is something like this.
zarch
March 13, 2013, 3:19pm
5
He only needs to enqueue it if he’s not already on the render thread.
For example if hes in an update, simpleInit, etc type method then he’s completely fine.
@zarch said:
He only needs to enqueue it if he's not already on the render thread.
For example if hes in an update, simpleInit, etc type method then he’s completely fine.
Right you are! I was thinking that he/she was not, due to this:
((Node)app.getViewPort().getScenes().get(0)).detachChildNamed(“Earth”);
It was such a round-about way of getting the root node, that I assumed they must be calling this from outside the render loop.