I’m finalizing my first game for Android. It is not a big revolution but I decided to start with a small project in order to learn about JME. Now, I would like to save the high score and other parameters on the mobile device. What is the recommended approach? I’ve been looking around the Savable interface and the BinaryExporter/Importer, but I cannot figure out how to use them on an Android platform and I’m not sure this is the technique recommended for android.
My approach is basic and simple works so far on all android devices I have tested.
It also works in all other OS’s.(Windows/Linux/etc.)
GameData.java
[java]
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
package za.co.tgiantlab.common.save;
You know we have a built in system in JME that does the same?
I use it for my android game and it works like a charm.
The thing is using the built in system you’ll have the same code on desktop and android.
Your GameData just have ti implement the Savable interface.
Than you have a SaveGame class with static methods like saveGame, loadGame and so on.
You also have to add a permission in your manifest
I let you read the last paragraph of the javadoc, but basically it’s because without an explicit declaration of it, it will be performed at runtime and could lead to some exception only because you made small change in your class, (maybe like changing the order of field declaration but this is an assumption).
Anyway, it’s strongly recommended to add it, so … yeah, you should add it.
This was purpose of my initial question: I wanted to star using the Savable class, but I was not sure to start with the best approach for android. Now I know Savable works with android too, I’ll try it!
The main issue I had to face was to find where to store the data… The code provided by ndebruyn was very helpful for that!
@dcaso said:
This was purpose of my initial question: I wanted to star using the Savable class, but I was not sure to start with the best approach for android. Now I know Savable works with android too, I'll try it!
The main issue I had to face was to find where to store the data... The code provided by ndebruyn was very helpful for that!