简体   繁体   English

在GKMatchmakerviewcontroller中处理取消

[英]Handling cancel in GKMatchmakerviewcontroller

I am making a multiplayer feature to a game I made. 我正在为我制作的游戏制作多人游戏功能。

Everything is working, except when I am in matchmaking and both players are connected, if one person hits the "Cancel" button the other device gets no notice of the canceling. 一切正常,除非我在配对中并且两个玩家都已连接,如果一个人点击“取消”按钮,则其他设备不会注意到取消。

On the other device it the words change to say "Disconnected" however none of the delegate methods are called. 在另一台设备上,单词更改为“Disconnected”,但是没有调用任何委托方法。

How can I handle this? 我怎么处理这个?

您应该实现GKMatchmakerViewControllerDelegate协议。

Unfortunately, there is not a method (that I know of, or could find with almost 3 months of looking into it) that is called when one person disconnects in matchmaking after they have begun to connect. 不幸的是,当一个人在他们开始连接后在配对中断开连接时,没有一种方法(我知道,或者可以在将近3个月的时间内找到它)。

Therefore, the way I got around this is once the GameViewController is presented it waits one second and then calls a method to check to see if it is connected to someone else. 因此,我解决这个问题的方法是,一旦GameViewController出现,它会等待一秒钟,然后调用一个方法来检查它是否与其他人连接。

To do this I have it so once the game begins each player sends the other player a random number (used to determine non-related settings later on - such as who gets to go first). 为了做到这一点,我有了它,所以一旦游戏开始,每个玩家向其他玩家发送一个随机数(用于确定以后的非相关设置 - 例如谁先去)。 When it calls the method to check to see if it is connected it just checks to see if the random number has been assigned. 当它调用方法来检查它是否已连接时,它只是检查是否已经分配了随机数。 If so, then it begins the game as normal, if not, it ends the game and pops back to the menu. 如果是这样,那么它就像正常一样开始游戏,如果没有,它就会结束游戏并弹回菜单。

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

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