简体   繁体   English

sendReliableMessage给自己? Google Play游戏服务 - Android

[英]sendReliableMessage to self? Google Play Game Services - Android

I am trying to create a real-time multiplayer game using Google Play Game Services. 我正在尝试使用Google Play游戏服务创建实时多人游戏。 I am trying to set one player as host. 我正在尝试将一名玩家设为主持人。 Everyone will send their commands to the host (via sendReliableMessage), and they will receive a response of what to render. 每个人都会将他们的命令发送给主机(通过sendReliableMessage),他们将收到要呈现的内容的响应。

However, I am trying to have the host send himself a message (before acting) in order to be in sync with everyone else, but the onRealTimeMessageReceived is not firing for the host when the host himself sends out the message. 但是,我试图让主机给自己发送一条消息(在执行之前)以便与其他人同步,但是当主机自己发出消息时,onRealTimeMessageReceived没有为主机触发。

Is it possible for the host to send a message to himself? 主持人可以向自己发送消息吗? If not, how would I go about this? 如果没有,我该怎么做呢? The Google tutorial even says I should have a host player. Google教程甚至说我应该有一个主机播放器。

You cannot do this using the sendReliableMessage() function in RealTimeMultiplayer class. 您不能使用RealTimeMultiplayer类中的sendReliableMessage()函数执行此操作。 As written here , the function throws an IllegalArgumentException if recipientParticipantId is not a valid participant or belongs to the current player . 至于写在这里 ,函数抛出IllegalArgumentException如果recipientParticipantId不是有效的参与者或属于当前玩家

The thing that you need to do is to forward all received messages (sent by others) to a common class/method etc (depending on your design/wish) to keep clients updated and keep your game logic running and call the class/method manually for the host. 您需要做的是将所有收到的消息(由他人发送)转发到公共类/方法等(取决于您的设计/愿望),以保持客户端更新并保持游戏逻辑运行并手动调用类/方法为主人。

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

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