Passing root node

I have a general design question I'm hoping someone can help me with. It seems that a number of classes need reference to the root node object and therefore I find myself passing the root node all over the place.

For example, I have a controller class that controls a fired projectile's movement. After several seconds, the projectile needs to be removed from the root node thus I passed the root node into the constructor of the controller class. Is there a way to get around this passing of the root node? I clearly don't want my controller object to known about the root node but I don't know of another way.

Any advice or pointers to a general design doc would be appreciated…


A Node is aware of it's own parent, so you can remove it without having your own reference, using removeFromParent().

I did have the same uncomfortable feeling when I started with jME, that I need to know about the root node everywhere. But in practice, with most things it's only when you have to attach them to it.

Yes, and better group them under nodes instead of directly to the root node.

Thanks Alric and Haladria.

Yes, I can see that removing the node from the parent will be easy.

...I did have the same uncomfortable feeling when I started with jME...

I find it comforting that I'm not the only one who has traveled down this road when learning JME.  :)


You could just use a getter method and do like a singleton class to go…

Class.GetInstance().getRootNode() I do that => - means you dont need to pass it anywhere!

1 Like