It's simple! You can use Preferences . You can save the values ββin the settings. On android, the backend uses SharedPreferences from Android itself. On the desktop, it is saved as xml somewhere in the user folder.
I wrote a simple helper to save options and get options for my game. Here is the code. (Please note, do not forget to start erasing after saving something)
public class PreferencesHelper { public final static String PREF_NAME_OPTION = "options"; private final static String VOLUMEN = "volumen"; private final static String VIBRATE = "vibrate"; private final static String EFFECT_VOLUMEN = "effect"; private final static String FIRST_START = "start"; private Preferences optionPref = Gdx.app.getPreferences(PREF_NAME_OPTION);; public PreferencesHelper() { optionPref = Gdx.app.getPreferences(PREF_NAME_OPTION); } public float getVolumen() { return optionPref.getFloat(VOLUMEN); } public void setVolumen(float vol) { optionPref.putFloat(VOLUMEN, vol); optionPref.flush(); } public boolean getVibrate() { return optionPref.getBoolean(VIBRATE); } public void setVibrate(boolean vibr) { optionPref.putBoolean(VIBRATE, vibr); optionPref.flush(); } public float getEffectVolumen() { return optionPref.getFloat(EFFECT_VOLUMEN); } public void setEffectVolumen(float eff) { optionPref.putFloat(EFFECT_VOLUMEN, eff); optionPref.flush(); } }
This is how I save my settings. To save the character, you do the same, but save all the things you import and need to recreate your character when you reload the game. You may also have more than one preventer!
Hope this helps.
source share