I know the Savable class is there, but is that what I would use? If so, how would I tell my game to save the class? Where does it save to? How would I load it again? Thanks in advance.
It’s up to you to write the data you wish to save and load it again, like so:
[java]
@Override
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
/**
* current value
* id
* default value to save if current is null
*/
oc.write(fogColor, "fogColor", ColorRGBA.White.clone());
oc.write(fogDensity, "fogDensity", 0.7f);
oc.write(fogStartDistance, "fogStartDistance", 200f);
oc.write(fogEndDistance, "fogEndDistance", 500f);
oc.write(excludeSky, "excludeSky", false);
}
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
fogColor = (ColorRGBA) ic.readSavable("fogColor", ColorRGBA.White.clone());
/**
* id
* default to use if it doesn't find the id
*/
fogDensity = ic.readFloat("fogDensity", 0.7f);
fogStartDistance = ic.readFloat("fogStartDistance", 200);
fogEndDistance = ic.readFloat("fogEndDistance", 500);
excludeSky = ic.readBoolean("excludeSky", false);
}
[/java]
Not really sure how to call this… probably
instance.save();
and for loading… got me. Everything in my game relies on serializable objects for storing/passing data, so I implemented a more specific way of handling this.
Yes you should use the jme serialization, it also instantiates whole networks of objects again (like the scenegraph in j3o’s).
I just used the SaveGame.class file, and made every class I wanted to save implement Savable. It works perfectly. I’m using this to save customized classes for my game. Here’s how I save and load each class:
When the player’s done editing, it calls:
[java]customizedClass.save();[/java]
In the “save()” method, I call:
[java]SaveGame.save(“Vinex/Lexicon”+Main.getUsername(), “CustomClass”+id, this);[/java]
Which saves it to C:\Users*login*\Vinex\Lexicon*username*\
On load, I call:
[java]customizedClass = (CustomClass)SaveGame.load(“Vinex/Lexicon/”+Main.getUsername(), “CustomClass”+id);[/java]
There’s obviously some checks to make sure it’s not null, and if it is to create and save a new instance, etc. But that’s the basic code for anyone else that has the same problem. It’s easily applicable to any case.