Game Center 按玩家添加到游戏的顺序获取玩家
我试图获取比赛游戏中所有玩家的数组,但按照他们添加到游戏中的顺序,这还必须指示本地玩家添加到游戏中的位置。
例如,以下人员按顺序加入(Sarah、Rachael、Me、John)。然后我可以得到一个数组,其中包括我自己在数组中的位置 2 吗?
感谢您的帮助
I am trying to get an array of all players in a match game but in the order they were added to the game this must also indicate the position the local player was added to the game as well.
E.g The following join (Sarah, Rachael, Me, John) in that order. Could i then get an array including myself in position 2 in the array?
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有类似的内置功能,但我是这样解决问题的:当您连接到游戏时,保存当前时间(
[NSDate date]
NSDate 存储的时间在 GMT 中非常精确时区,所以不用担心时区混乱)。当您需要构建数组时,您可以请求其他客户端加入的时间,然后使用差异来确定谁先加入。如果您使用客户端/服务器基础设施,其中一个对等方扮演服务器,您可以在那里构建阵列,但只需从加入的客户端发送握手,然后服务器就会维护与客户端的列表。希望这有帮助。
There is nothing like this built in, but here is how I would solve the problem: When you connect to the game, save the current time (
[NSDate date]
NSDate stores the time pretty precise in the GMT time zone, so no worry about time zone mess ups). When you need to build the array, you can request the times the other clients joined and then use the differences to determine who joined first.If you use a client/server infrastructure where one peer plays the server, you can build the array there but just sending a handshake from the joined client, the server then maintains the list with clients. Hope this helps.