问题
I have been developing a game for Game Center.
Description of game :-
One player is initiator of game because game has 5 tiled-map (only one tile-map is selected randomly by either player(initiator)) . Initiator will send selected tile-map to second player, Now this tile-map will draw on second player side.(at this point both player have same tile-map)
This is work fine when I start game by sending invitation to player.
but when I start game by "automatch" , I am not able to find that who will be the initiator(who will send randomly selected tile-map).
I have made one player initiator by this code:
isThisInvited_Player = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_INVITATION_ACCEPTED object:nil];
- (void)authenticationChanged {
if ([GKLocalPlayer localPlayer].isAuthenticated && !userAuthenticated) {
userAuthenticated = TRUE;
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
isThisInvited_Player = YES;
self.pendingInvite = acceptedInvite;
self.pendingPlayersToInvite = playersToInvite;
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_INVITATION_ACCEPTED object:nil];
};
} else if (![GKLocalPlayer localPlayer].isAuthenticated && userAuthenticated) {
userAuthenticated = FALSE;
}
}
if data sync is not possible in "automatch", then please tell me , how can I disable the automatch(Play) button in game-center-view-controller.
回答1:
You could pick who the initiator is by sorting the two players by their playerIDs and then always have the first one in the sorted array be the initiator.
来源:https://stackoverflow.com/questions/13820097/how-to-sync-data-in-multiplayer-gamegame-center-ios