libGDX save and load game data

So you want to load and save some data in your game, a good way is via a JSON file.

In your main class:

	public void create () {
		batch = new SpriteBatch();
		setScreen(new IntroScene(this));

Set up a GameData class:

public class GameData {

  private int highscore;
    private boolean musicOn;

  public int getHighscore() {
    return highscore;

  public void setHighscore(int highscore) {
    this.highscore = highscore;

  public boolean isMusicOn() {
    return musicOn;

  public void setMusicOn(boolean musicOn) {
    this.musicOn = musicOn;

And set up a GameManager class:

  private static GameManager ourInstance = new GameManager();

  public GameData gameData;
  private Json json = new Json();
  private FileHandle fileHandle = Gdx.files.local("bin/GameData.json");
  private GameManager() {}

  public void initializeGameData() {
    if (!fileHandle.exists()) {
      gameData = new GameData();


    } else {

  public void saveData() {
    if (gameData != null) {

  public void loadData() {
    gameData = json.fromJson(GameData.class,
    public static GameManager getInstance() {
    return ourInstance;

Game data will be loaded if the is JSON file in “bin/” else a file will be created. The file will be encoded so it will be hard to manipulate by a user.