【问题标题】:Google Play Games Realtime Multiplayer: How to get the participant id of the current user?Google Play Games Realtime Multiplayer:如何获取当前用户的参与者 ID?
【发布时间】:2017-03-17 02:18:53
【问题描述】:

我正在开发一款使用 Google Play Games Realtime Multiplayer 的 Android 游戏。

我想确定哪个设备是比赛的创建者/发起者,以便两台设备都知道哪个设备正在做所有事情计算,消息发送等

所以本质上,我需要找到一种方法来获取正在执行代码的用户的参与者 ID;我可以从那里处理比较值。​​

【问题讨论】:

  • 这可以在实时多人游戏中使用吗?
  • 你永远不会知道如果你不尝试
  • 我终于开始测试它了,它可以工作了!!

标签: java android google-play-games


【解决方案1】:

尝试使用Games.Players.getCurrentPlayer(getApiClient()),在此SO thread 中已提及。

public String myParticipantID(){
    return match.getParticipantId(Games.Players.getCurrentPlayer(gac).getPlayerId());
}

【讨论】:

    【解决方案2】:

    使用 Games.Players api 获取当前玩家 id,然后您可以使用 Room api 获取当前参与者 id。

    String playerId = Games.Players.getCurrentPlayerId(mGoogleApiClient);
    String currentParticipantId = room.getParticipantId(playerId);
    

    其中房间是Room 对象,mGoogleApiClient 是GoogleApiClient 对象。

    【讨论】:

      猜你喜欢
      • 2019-02-01
      • 2023-04-04
      • 2017-02-02
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 2016-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多