how to sync data in multiplayer game(game-center ios)

喜你入骨 提交于 2020-01-06 07:47:05

问题


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

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