我一直在尝试使用getPreferences保存分数来在我的Libgdx游戏中实现高分功能。当我将程序作为桌面应用程序运行时,它会在初次使用后保存分数,但是当我关闭并重新运行它时,这些分数不会保留。当游戏发布到android,ios,台式机等上时,即使程序终止,它也将完全保留吗?

这是我正在使用的代码:

Preferences scores = Gdx.app.getPreferences("High Scores");


int currentHighScore = scores.getInteger("currentHighScore", 0);
                        if(currentHighScore < gamescore){
                        scores.putInteger("currentHighScore", gamescore);

int currentHighScore = scores.getInteger("currentHighScore",0);

最佳答案

您必须确保在应用程序退出之前调用flush()。在调用scores.flush()之后添加putInteger(...)就足够了。

https://github.com/libgdx/libgdx/wiki/Preferences

07-26 04:39