I know I have asked this question so similar before but I get there no more answer ... I would like, as soon as I lost in my game, my HighScore displayed. Here is the code:
First you get the object:
Preferences preferences = Gdx.app.getPreferences("My preferences");
Then, when you lose in your game, you get the value. I usually check if I lose in the render method with a boolean. In this case you compare your highscore with your current score:
if(IsGameFinished)
{
int highscore = preferences.getInteger("High score",0);
if(highscore>=yourCurrentScore)
{
// display highscore
}
else
{
// display yourCurrentScore
preferences.putInteger("High score", yourCurrentScore);
preferences.flush();
}
}
Furthermore in your code there is an error:
protected Preferences HighScore () {
if (score > highscore) {
prefs.putInteger("highscore", score);
prefs.flush(); // YOU SHOULD FLUSH BEFORE!
this.highscore = prefs.getInteger("highscore", 0);
}
return prefs;
}
And, why do you return the Preferences? Returning your highscore as an int should be better.