初次登录后,即使离线,GPGS也可以让用户保持“已登录”状态。所以,我可以玩,好像我已经连接,然后,当我有实际连接时,我的分数/成就会被同步。
这很好,但在离线时尝试从排行榜中检索分数似乎不起作用:
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(
gameHelper.getApiClient(),
LD_ID,
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<LoadPlayerScoreResult>(){
@Override
public void onResult(LoadPlayerScoreResult arg0) {
LeaderboardScore c = arg0.getScore();
Player.bestScore = (int)c.getRawScore();
}
});
在线时,c.getRawScore()按预期工作,但在离线状态时,c为空(令我惊讶的是,因为我认为如果离线,它会回退到缓存的分数。)
有没有办法获得缓存的排行榜得分?
答案 0 :(得分:0)
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(
gameHelper.getApiClient(),
LD_ID,
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>(){
@Override
public void onResult(LoadPlayerScoreResult res) {
Status status = res.getStatus();
int statusCode = status.getStatusCode();
if (statusCode == GamesStatusCodes.STATUS_NETWORK_ERROR_NO_DATA) {
System.out.println("A network error occurred while attempting to retrieve fresh data, and no data was available locally.");
} else if (statusCode == GamesStatusCodes.STATUS_NETWORK_ERROR_STALE_DATA) {
System.out.println("A network error occurred while attempting to retrieve fresh data, but some locally cached data was available. The data returned may be stale and/or incomplete.");
} else {
System.out.println(status.getStatusMessage());
}
}
});
我没有测试过这段代码,但它应该可行。这是一些帮助您解决问题的调试代码。在线和离线时运行此命令,并查看每种情况下的结果。