I want to know if I can just implement sqlite database for android in libgdx game? Also if this is not possible then may I know the simple way to integrate libgdx game to just store scores in sqlite database. I dont want to use preference or jason because I have to get last stored scores and then level wise comparison of scores.
-
\$\begingroup\$ Questions asking "is it possible" are yes-or-no questions, which are generally poor questions for the SE format. The implicit follow up ("how can I...") is too broad with the limited information you've provided and probably isn't particularly game-development specific anyway (so should be asked on SO). \$\endgroup\$– user1430Commented Dec 22, 2014 at 18:52
-
\$\begingroup\$ Ók. I am new here so I was not knowing how to ask. Thank you for pointing out my mistakes. \$\endgroup\$– Aiman BatulCommented Dec 23, 2014 at 4:19
1 Answer
To use platform specific code in libgdx you make an interface in your core project.
interface SaveScore {
public void saveScore(int score);
}
And then make an implementation in your android project and any other projects you might have (desktop, ios and so on).
public class SaveScoreAndroid implements SaveScore {
public void saveScore(int score) {
//Platform specific code goes here
}
}
Then you make your application listener take in an implementation of the interface as an argument in the constructor. Now you can pass in the platform specific implementation of the interface in the starter class of your android project.
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGame(new SaveScoreAndroid()), config);
}