1

Probably a stupid question, but what do I have to change to make this code work:

package com.hobogames.WizardsDuel;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;

public class GameData {
    public static String version = "1.0.0";

    public static String data[] = {"version"};
    public static final int VERSION = 0;

    public static Preferences prefs = Gdx.app.getPreferences("WizWars");
    public static boolean played = (!prefs.get().isEmpty());

    public static String getString(int key){
        return prefs.getString(data[key]);
    }

    public static void storePrefs(){
        prefs.putString(getString(VERSION),version);
        prefs.flush();
    }
}

The part in particular that isn't working is that "played" is false every time on an android device. On desktop it's true after the first play.

4

1 回答 1

2

我怀疑你被staticAndroid 和桌面上的行为不同的状态所困扰。当您在 Android 上退出应用程序时,您确定 VM 会退出吗?如果你在 Android 上快速重启你的应用,系统会为新的 Activity 重用同一个 Dalvik VM。由于static boolean已经初始化,因此不会重新运行初始化。如果你删除了,static所以这些东西在创建时会重新运行GameData(可能它的实例没有存储在静态变量中)你应该走得更远。

http://bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/

于 2013-06-14T05:33:06.693 回答