So I basically have a model(in j3o format), that I want to load into a game and then when the game is stopped, the model is saved and loaded again. So everytime I run the program there would be one more model in the game. My problem is, I want to have the saved j3o loaded in a folder called SavedGames. However, the code below works, because everytime the game runs i see the model loaded, but there is no folder called SavedGames generated in my assets folder.
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.export.binary.BinaryExporter;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
-
test
-
@author normenhansen
*/
public class Main extends SimpleApplication {public static void main(String[] args) {
//specify your settings here
Main app = new Main();app.start();
}
@Override
public void simpleInitApp() {
//load model from save
String userHome = System.getProperty(“user.home”);
assetManager.registerLocator(userHome, FileLocator.class);
try{
Node loadedNode = (Node) assetManager.loadModel("/SavedGames/savedgame.j3o");
rootNode.attachChild(loadedNode);
}catch (com.jme3.asset.AssetNotFoundException e){}//display model Spatial mymodel = assetManager.loadModel("Models/MyModels/mymodel.j3o"); mymodel.move(FastMath.nextRandomFloat()*2-5, FastMath.nextRandomFloat()*2-5,FastMath.nextRandomFloat()*2-5); rootNode.attachChild(mymodel); DirectionalLight sun = new DirectionalLight(); sun.setDirection((new Vector3f(-0.5f,-0.5f,-0.5f))); sun.setColor(ColorRGBA.White); rootNode.addLight(sun);
}
@Override
public void stop(){
//save model
String userHome = System.getProperty(“user.home”);
File file = new File(userHome + “/SavedGames/” + “savedgame.j3o”);
BinaryExporter exporter = BinaryExporter.getInstance();
try{
exporter.save(rootNode, file);
}catch(IOException ex){
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, “Error: Failed to save game!”, ex);
}
super.stop();
}@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]