如何使用gdx-gamesvcs将游戏数据保存到云中?

问题描述

我想在libgdx引擎的游戏中实现Google Play游戏服务。我尝试为此使用gdx-gamesvcs。但是我在保存数据时遇到了麻烦。我从示例中了解到,保存的是一个值,而不是游戏的整个状态。因此,我决定进行检查:使用gsClient.loadGameStategsClient.saveGameState保存并加载一个值。我特意从设备中删除了游戏数据。但是结果是,不仅测试值发生了变化,许多其他值也发生了变化。我以为是保存了整个游戏的状态,但是获得的值不适合游戏的逻辑并且无法在其中获得。 我应该如何使用此工具,它是否值得使用?还是使用libgdx本身提供的功能更好? 这是一段代码:

if (gsClient.isSessionActive()) {
            try {
                gsClient.saveGameState("data",intToByteArray(testValue),null);
            } catch (UnsupportedOperationException unsupportedOperationException) {
}


if (gsClient.isSessionActive()) {
            try {
                gsClient.loadGameState("data",new ILoadGameStateResponseListener() {
                    @Override
                    public void gsGameStateLoaded(byte[] gameState) {
                        if (gameState != null) {
                            setTestValue(bytesToInt(gameState));
                        }
                    }
                });
            } catch (UnsupportedOperationException unsupportedOperationException) {
            }
}

UPD 是的,保存同时发生在云和设备上,为了保存到我使用首选项的设备。我在游戏中有一个Google帐户登录按钮,它可以正常工作,我反复看到我的帐户级别的此标准栏,该栏在我登录时显示在顶部。所有内容也都在开发人员控制台中设置,我有一个ID成就和排行榜。在代码中,我是这样与客户端一起工作的(在create()方法中):

public IGameServiceClient gsClient;

if (gsClient == null) {

            gsClient = new MockGameServiceClient(1) {
                @Override
                protected Array<ILeaderBoardEntry> getLeaderboardEntries() {
                    return null;
                }

                @Override
                protected Array<String> getGameStates() {
                    return null;
                }

                @Override
                protected byte[] getGameState() {
                    return new byte[0];
                }

                @Override
                protected Array<IAchievement> getAchievements() {
                    return null;
                }

                @Override
                protected String getPlayerName() {
                    return null;
                }
            };
        }
        gsClient.setListener(this);
        gsClient.resumeSession();

下一个正在加载。
没有捕获到异常,我将其删除,一切正常。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)