检测其他玩家是否意外离开(例如互联网断开连接)并重新连接 - Google玩实时多人游戏 [英] Detect if other player left unintentionally (e.g. internet disconnection) and reconnect - Google play real time multiplayer

查看:213
本文介绍了检测其他玩家是否意外离开(例如互联网断开连接)并重新连接 - Google玩实时多人游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



目前,如果我在一个客户端关闭WIFI,另一个客户端不会检测到连接是丢失。没有PeerDisconnect事件被调用。



<1> - API是否提供任何内容来检查对方是否仍然连接?



2 - 是否有任何方法让玩家重新连接到房间?

解决方案

1 - API提供任何东西来检查对方是否仍然连接?



RoomStatusUpdateListener 回调来监控参与者的连接状态。正如所述:


要在所有玩家连接时得到通知,您的游戏可以使用 RoomUpdateListener.onRoomConnected() 回调。您的游戏还可以使用 RoomStatusUpdateListener 回调来监控参与者的连接状态。根据参与者的连接状态,您的游戏可以决定是否开始或取消游戏会话。


<2>任何方式让玩家重新连接到房间?



实时多人游戏 - Gameplay 指出:


一个房间的所需参与者人数已经连接,该房间被认为是充满并且可以开始玩游戏。参与者加入房间后,您的游戏可以让他们离开房间(有效地将他们从游戏中删除)。但是,没有新玩家可以在填充之后加入房间<甚至不填补参与者腾空的地点。


除此之外,请参阅最佳做法实时多人游戏 b
$ b


如果您没有适当离开房间,Google Play游戏服务将继续发送活动并向客户发送邀请通知。每当发生以下情况时,您都应该离开活动房间: 游戏结束了(例如,玩家赢了比赛)。

  • 当您的游戏进入后台时。

  • 在Android上,请在以下时间离开房间:

      $
    • onActivityResult()中返回的响应代码。b $ b
    • 玩家在候补室UI中取消游戏。回调是
      GamesActivityResultCodes.RESULT_LEFT_ROOM

    • 活动 onStop()被调用。这可能表明您的
      活动正在销毁。在这种情况下,请离开房间并拨打$ ​​b $ b disconnect()



  • 希望这些链接能够涵盖您的所有疑虑。快乐的编码! :)

    I am implementing google play game service real time multiplayer.

    Currently if I turn off the WIFI on one client the other client doesn't detect that the connection is lost. No PeerDisconnect events are called.

    1 - Does the API provide anything to check if the peer is still connected?

    2 - Is there any way to let the player reconnect to the room?

    解决方案

    1 - Does the API provide anything to check if the peer is still connected?

    As stated in Connecting players, you can monitor the connection status of the participants with the use of RoomStatusUpdateListener callbacks. As stated:

    To be notified when all players are connected, your game can use the RoomUpdateListener.onRoomConnected() callback. Your game can also use the RoomStatusUpdateListener callbacks to monitor the connection status of the participants. Based on the participant connection status, your game can decide whether to start or cancel the gaming session.

    2 - Is there any way to let the player reconnect to the room?

    Real-time Multiplayer - Gameplay states that:

    Once the required number of participants for a room have been connected, the room is considered to be 'filled' and gameplay can begin. After participants join a room, your game can allow them to leave the room (effectively dropping them out of the game). However, no new players can join a room after it is 'filled' (not even to fill a spot that a participant has vacated).

    In addition to that, referring to best practice for Real-time multiplayer:

    If you don't leave the room appropriately, Google Play games services will continue to send event and invitation notifications to the client. You should leave the active room whenever one of these scenarios occurs:

    • Gameplay is over (for example, a player has won the match).
    • When your game goes into the background.
    • On Android, leave the room when:
      • The player cancels the game in the waiting room UI.
      • The response code returned in the onActivityResult() callback is GamesActivityResultCodes.RESULT_LEFT_ROOM.
      • The Activity onStop() is called. This might indicate that your Activity is being destroyed. In this case, leave the room and call disconnect().

    Hope those links covers up all your concerns. Happy coding! :)

    这篇关于检测其他玩家是否意外离开(例如互联网断开连接)并重新连接 - Google玩实时多人游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆