如何在多人游戏中同步数据(游戏中心ios) [英] how to sync data in multiplayer game(game-center ios)
问题描述
我一直在为游戏中心开发一款游戏。
I have been developing a game for Game Center.
游戏说明:
一个玩家是游戏的发起者,因为游戏有5个平铺地图(任何一个玩家(发起者)只能随机选择一个平铺图)。发起人将选定的瓷砖地图发送给第二个玩家,现在这个瓷砖地图将在第二个玩家方面绘制。(此时两个玩家都有相同的瓷砖地图)
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;
}
}
如果无法进行数据同步automatch,那么请告诉我,如何在游戏中心视图控制器中禁用自动匹配(Play)按钮。
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.
推荐答案
您可以通过播放器ID对两个播放器进行排序,然后始终将排序后的阵列中的第一个播放器作为发起者来选择发起者是谁。
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.
这篇关于如何在多人游戏中同步数据(游戏中心ios)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!