开发者

Developing a game

iam using libgdx开发者_如何转开发 for developing a touch based game.In my game i would like to save the state and want to restore it at some particular time. Is there any way in libgdx or any other way?


If by saving state you mean saving and loading settings/preferences, use this:

Preferences prefs = Gdx.app.getPreferences("my-preferences");
prefs.putBoolean("bool", true);
prefs.putInteger("int", 1234);
prefs.putLong("long", Long.MAX_VALUE);
prefs.putFloat("float", 1.2345f);
prefs.putString("string", "test!");

if(prefs.getBoolean("bool") != true) throw new GdxRuntimeException("bool failed");
if(prefs.getInteger("int") != 1234) throw new GdxRuntimeException("int failed");
if(prefs.getLong("long") != Long.MAX_VALUE) throw new GdxRuntimeException("long failed");
if(prefs.getFloat("float") != 1.2345f) throw new GdxRuntimeException("float failed");
if(!prefs.getString("string").equals("test!")) throw new GdxRuntimeException("string failed");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜