【问题标题】:How to make CommitBlocking commit ? -- Google Play Game Services如何使 CommitBlocking 提交? -- Google Play 游戏服务
【发布时间】:2016-06-25 09:18:50
【问题描述】:

我正在使用 cocos2d-x for android 做一个小游戏。我目前正在努力为我的游戏实施 Cloud Save。剩下的唯一问题是它没有提交。

我使用的 GPGS API 是 C++。只需向下滚动到那里的 commitblocking。

//using sample codes from Google.
game_services->Snapshots().Open
(
    "some_save_file",
    gpg::SnapshotConflictPolicy::MANUAL,
    [this, &save](gpg::SnapshotManager::OpenResponse const& response)
    {
        LOGI("Saving snapshot");
        if(gpg::IsSuccess(response.status))
        {
            LOGI("Open success");
            gpg::SnapshotMetadata metadata = response.data;
            if (response.conflict_id != "")
            {
                //Conflict detected
                //Settle conflict
            }

            LOGI("Getting PNG data");
            //get cover image data
            //some code to get png data in to png_vector

            LOGI("Building snapshot builder");
            //setting up the builder
            gpg::SnapshotMetadataChange::Builder builder;
            gpg::SnapshotMetadataChange metadata_change =
                    builder
                    .SetDescription("Recall Save File")
                    .SetCoverImageFromPngData(png_vector)
                    .Create();

          LOGI("Commiting");
          // Save the snapshot.
          // This is the part that does not work !!!!!
          gpg::SnapshotManager::CommitResponse commitResponse =
              game_services->Snapshots().CommitBlocking(gpg::Timeout(3000), response.data, metadata_change, save);

          if (IsSuccess(commitResponse.status))
            CSH_LOGI("Saved game");
          else
            CSH_LOGI("Saved game failed error: %d", commitResponse.status);
    }
);

在手机上编译和运行时:

    06-25 16:51:47.405: V/GamesNativeSDK(10717): Snapshot was not committed, discarding.
    06-25 16:51:47.410: V/GamesNativeSDK(10717): Snapshot discard complete.

我曾尝试使用 Commit(),这会使游戏崩溃,而 CommitBlocking() 没有超时,它也不会提交。

我花了将近一周的时间查看文档和示例来解决这个问题。那么,以前有人遇到过这个问题吗?如果有,请与我分享如何解决。

谢谢。

【问题讨论】:

  • 您是否首先使用 EnableSnapshots() 启用了快照?在 Github 中查看完整的 C++ save implementation 示例。对你有很大帮助。
  • 是的,我做到了。我发现了一些错误并解决了它们。谢谢:D

标签: c++11 cocos2d-x google-play-games


【解决方案1】:

好的,有一些奇怪的错误。

1) 将保存返回为 std::vector 保存以用于 CommitBlocking 的方法仅返回大小为零的向量。

2)Png 数据太大,Google Cloud Save 无法接受。

在得到1)中所述的方法返回正确的数据并最小化和无松散地压缩2)中使用的Png后,确实解决了问题。

【讨论】:

    猜你喜欢
    • 2014-02-02
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2013-07-31
    • 2017-09-27
    • 2018-05-09
    • 1970-01-01
    相关资源
    最近更新 更多