Hi,
my application starts and stops the game as per the nifty gui buttons. I have made appstates such as RunningGame, MainMenuAppState etc. When I detach the Running game appstate it doesnt automatically destroy that appstate and all the previous objects remain attached to rootNode. is there a way to completely destroy previous appstates so that I can start a clean and new instance of those appstates?? I’m also concerned about my assetmanager objects. How could I be sure that I have removed all objects attached to simpleapplication object and freed my memory??
How about if I run all my nifty thing in one simpleapplication extended appstate and run my game in another simpleapplication appstate and then I can do runnGame.stop() to destroy all the assets that it contains.
Your app state needs to clean itself up in cleanup(). There is no magic. Your app state adds stuff so your app state must remove it again. JME has no idea what it’s done and so couldn’t possibly do this automatically.
But there isn’t any tutorial explaining how to do this effectively??
Is detachAllChildren() going to remove all my objects from rootNode??
How should I remove instances of nodes like shootables etc??
If I have created an object in one of my appstates (global private), how should I destroy it??
Will detaching an appstate, destroy that object as well??
I have implemented the cleanup() function to remove allChildren of rootNode and guiNode?
But when I attach a new appstate using statemanager.attachState(new RunningGameAppState()) it loads a white colored scene. I have no idea whats happening?
@Override
public void setEnabled(boolean enabled) {
// Pause and unpause
super.setEnabled(enabled);
if (enabled) {
//Settings
setUpCamera();
setUpLight();
setUpSceneGraph();
initCrossHairs();
initHUD();
System.out.println(“Started”);
//app.getStateManager().attach(new StatsAppState());
//app.getStateManager().attach(new FlyCamAppState());
//app.getStateManager().attach(new DebugKeysAppState());
} else {
//take away everything that is not needed while this state is paused
}
}
@Override
public void update(float tpf) {
//do the following while game is running //this.app.getRootNode().getChild(“Box”).scale(tpf*2);
// Update HUD
}
/**
A centred plus sign to help the player aim.
*/
private void initCrossHairs() {
AppSettings settings = new AppSettings(true);
BitmapFont guiFont;
private void initHUD() {
BitmapFont guiFont = app.getAssetManager().loadFont(“Interface/Fonts/Default.fnt”);
BitmapText hudText = new BitmapText(guiFont, false);
hudText.setSize(guiFont.getCharSet().getRenderedSize()); // font size
hudText.setColor(ColorRGBA.Blue); // font color
hudText.setText("Time Left: "); // the text
hudText.setLocalTranslation(0,hudText.getHeight(), 1); // position
app.getGuiNode().attachChild(hudText);
Reminder timer = new Reminder(hudText,30);
timer.setUpdateInterval(1);
}
}
[/java]
My question is what else are the possibilities about removing what all it added??
I’ve got a question regarding the detachment of all children. Am I supposing right that I don’t have to remove any spatial - like geometries I’ve created - manually but only things like lights that aren’t actually spatials?
deatchAllChildren() detaches all of the children. If something is not a child then a different method has to be used to remove it. Lights are not children. Only spatials are children in this context.