I am having problems with some of my code and removing controls AND nodes; here is the code (pastebinned for convenience):
The Control class: http://pastebin.com/4jnzP8cq
The class where I make all of the ‘traps’, and attach them to the node (the rootNode in this case): http://pastebin.com/iWiSmMFt
and the code which I call in my main class to create the traps (which is called from simpleInitApp()
public void initTraps() {
Material trapmat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
trapmat.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
trapfactory = new TrapFactory(traplist, trapmat, bulletAppState, TrapNodeName, TrapName, PlayerNodeName, rootNode);
trapfactory.parseFile("map.txt");
trapfactory.attachMapToNode(rootNode);
traplist = trapfactory.gettraplist();
}
I call trapfactory.checkForUsedTraps(); in my main class’ update loop.
My issue is in TrapControl’s function(); calling that method, every ‘trap’ and its hitbox gets removed. If I comment out the third line in function, all of the Geometries are still floating in the air, and when I comment out the first line (uncommenting the third), all of the Geometries are removed but the hitbox is still there, as well as the PhysicsCollisionListener still being active.
The desired behavior is the individual trap detaching its hitbox and geometry from the scene, as well as the PhysicsCollisionListener later being removed from the Physics Space.
How I am interpreting what my function() call should be doing as I coded it:
gets the spatial’s hitbox Physics Space which it is currently attached to, and removing the Spatial’s RigidBodyControl from that space (but not touching that of any other spatial).
removes the spatial from the parent (the rootNode) (again, not affecting any other spatial).
I would be inclined to think that it is a problem with how I set up the first statement, but the way that spatial.removeFromParent() behaves makes me think that it is my approach.
I am a novice at JME, and any advice would be appreciated. I can post all of my code, but as of posting I feel like that would be overkill as a lot of it seems irrelevant.
Thanks!