0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\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\$
    – user1430
    Commented 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\$ Commented Dec 23, 2014 at 4:19

1 Answer 1

0
\$\begingroup\$

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);
}
\$\endgroup\$
0

Not the answer you're looking for? Browse other questions tagged .