简体   繁体   English

如何在实时多人Google Play游戏服务中创建房间时向其他参与者发送数据

[英]How to send data to other participant on Room creation in Real-time Multiplayer Google Play Game Services

I am developing an android application in which I integrated the Real-time Multiplayer of Google Play Game Services. 我正在开发一个Android应用程序,其中集成了Google Play游戏服务的实时多人游戏。 Everything is working well, but I still need to send unified value between all the participants before the beginning of the game (in Quickplay and when a user invites other players to a room)... I read in the "Real-time Multiplayer of Google Play Game Services" docs that a user can be choosen as the host of the game, but how can I do so and how can send these data to other participants before the beginning of the Game?? 一切运行良好,但我仍然需要在游戏开始之前(在Quickplay中以及当用户邀请其他玩家进入游戏室之前)在所有参与者之间传递统一的价值。 Google Play游戏服务”文档,可以选择用户作为游戏主机,但是我该怎么做以及如何在游戏开始之前将这些数据发送给其他参与者?

Thanks in advance :) 提前致谢 :)

You have to implement your own logic for this. 您必须为此实现自己的逻辑。 The gps just sets up the peer-to-peer connection for you. GPS只是为您设置了对等连接。 After that it calls the onRoomConnected() callback. 之后,它将调用onRoomConnected()回调。

This should be the point you decide which client should be your "host". 这应该是您决定哪个客户端应作为“主机”的关键。 You could do this by the random by choosing it depending on the clients ID, eg the "greatest" ID is the server, cause the ID is known for all clients and there is no communication needed, to find out who is the "host" on every device. 您可以根据客户端ID随机选择它,例如,“最大” ID是服务器,原因是该ID对所有客户端都是已知的,并且不需要通信,即可找出谁是“主机”在每台设备上。 If you want another logic for this, you could have every client calculate some value, send it to the others and decide from these values. 如果您需要其他逻辑,则可以让每个客户端计算一些值,然后将其发送给其他客户端,然后从这些值中进行确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM