Game Center Finding a Match Programmatically

后端 未结 3 947
青春惊慌失措
青春惊慌失措 2021-02-13 16:00

I just can\'t figure out how this works. What I am trying to do is let two players play a game if a third player joins it can instantly join the game, if the fourth and last pla

相关标签:
3条回答
  • 2021-02-13 16:11

    I would suggest that you periodically (maybe once per second or two) poll for the status of other players, so you can detect if anyone has joined, or left for any reason. Unless the iphone architecture you are using already provides an function that handles that event.

    It sounds like you may want to find some more documentation and/or sample code for the multi-player framework you are using.

    0 讨论(0)
  • 2021-02-13 16:31

    Which device should actually call the addPlayersToMatch method? And how can you restrict it to one device executing that method?

    You could solve this problem by having the devices "draw straws". Each device generates a random number, then sends it to the others. The device with the largest number is the leader, and it is the one that must call addPlayersToMatch. If two devices pick the same number, throw out the numbers and start over.

    0 讨论(0)
  • 2021-02-13 16:32

    Your using the Apple iOS Game Center GKMatchmaker class. I'm assuming you are using a peer to peer connection, not hosted.

    The GKMatch class gives the playerIDs array to you.

    @property(nonatomic, readonly) NSArray *playerIDs
    

    This is an ordered list, so you might be able to use it to select the first player call addPlayersToMatch.

    Linked below is some documentation.

    http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKMatchmaker_Ref/Reference/Reference.html

    http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKMatch_Ref/Reference/Reference.html

    http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008304

    0 讨论(0)
提交回复
热议问题