iphone - Game Center Finding a Match Programmatically -
i can't figure out how works. trying let 2 players play game if third player joins can instantly join game, if fourth , last player joins can instantly join game. can leave game @ anytime whatever reason, if happens there should space open person or same person reconnect. that's idea.
now got following. authenticate local player obvious reasons. search match so:
if (matchrequest) [matchrequest release]; matchrequest = [[gkmatchrequest alloc] init]; matchrequest.minplayers = 2; matchrequest.maxplayers = 4; [[gkmatchmaker sharedmatchmaker] findmatchforrequest:matchrequest withcompletionhandler:^(gkmatch *match, nserror *error) { if (error) { // error occured } else { if (matchcurrent) [matchcurrent release]; matchcurrent = [match retain]; matchcurrent.delegate = self; } }];
if execute part on 3 different devices, 2 of them find each other , third still looking. figured after find match request has found minimum amount of players executed once. needed method used matchcurrent retained add more players. luckely method existed, how work? when call in case? decided put under button manually execute when match has been found.
what discovered when pressed on first device, third device find match first , second device in. in fact second , third device contained playerids of every device involved. thing. there 2 problems.
- which device should call addplayerstomatch method? , how can restrict 1 device executing method? plus when should call it?
why, on device calling method, isn't playerids updated?
[[gkmatchmaker sharedmatchmaker] addplayerstomatch:matchcurrent matchrequest:matchrequest completionhandler:^(nserror *error) { //matchcurrent.playerids not updated?! }];
actually updated. when see playerids appear on second , third device manually update matchcurrent.playerids on device 1 , recognize player. 'didchangestate' player not called when new player discovered on device one.
your using apple ios game center gkmatchmaker class. i'm assuming using peer peer connection, not hosted.
the gkmatch class gives playerids array you.
@property(nonatomic, readonly) nsarray *playerids
this ordered list, might able use select first player call addplayerstomatch.
linked below documentation.
Comments
Post a Comment