It is necessary to save the best result. What are the options for saving?
I do not use libgdx.
SharedPreferences prefs = this.OnSharedPreferenceChanged("myPrefsKey", Context.MODE_PRIVATE); best = prefs.getInt("score", 0); if (best > player.getScore()) { canvas.drawText("BEST: " + best, WIDTH - 215, HEIGHT - 10, paint); } else { best = player.getScore(); canvas.drawText("BEST: " + best, WIDTH - 215, HEIGHT - 10, paint); prefs.edit().putInt("score", best).apply(); }
Solved a problem. For me, this code came up:
SharedPreferences prefs = this.getContext().getSharedPreferences("BEST", Context.MODE_PRIVATE); In general, SharedPreferences is a very tricky thing.
Any Context is required and consider this! In my case - I registered the code when creating a new game and at the end. This, too, consider!