My GKMatch has no players…?

大憨熊 提交于 2019-12-24 19:03:24

问题


  • I successfully made a matchmaking screen appear.
  • I run my game in my iPhone and also in the simulator.
  • In both cases I log in with a different Game Center account.
  • I go to the matchmaking screen in both games. I press "play now". Both games begin looking for a match.
  • Finally, both games find a match and call the function below:

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
    self.myMatch = match;
    NSLog(@"%d",[[self.myMatch playerIDs]count]);

}

But my console returns 0. Shouldn't it return 2 instead?


回答1:


Could it be that you are not actually connecting them?

Are you in fact using GKMatchmaker and GKMatchmakerViewController?

In your testing, you are sure you are using TWO DIFFERENT game center accounts?

I'm afraid I'm not familiar with the game center system.




回答2:


GKMatchmaker returns you a match before connections have been established between players; at this stage, all the players are in the process of connecting to each other.

The playerIDs property is initially set to the number of players already connected to the match; the array may be empty. Whenever a player is connected to the match, that player’s player identifier is added to the array.

Additionally, some players can fail to connect (I haven't tested this case so I don't know if you get an error returned)

What you're looking for is GKMatch.expectedPlayerCount

The value of this property is decremented whenever a player connects to the match. When its value reaches zero, all expected players are connected, and your game can begin the match.

I also suspect that GKMatch.playerIDs does not include the player; i.e. you'll probably see expectedPlayerCount = 1 immediately after connecting.

I'm not sure what GameKit does about threads.



来源:https://stackoverflow.com/questions/5527236/my-gkmatch-has-no-players

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!