游戏中心主机

发布于 2024-12-11 09:27:59 字数 127 浏览 2 评论 0原文

我目前正在创建一个 Game Center 游戏,并使用可用的点对点功能。但是,我想选择其中一名玩家(2名玩家)作为主机,以确保同步。

从可用的玩家中选择主机(甚至是随机的)并确保其他设备知道选择了哪个主机的最佳方法是什么?

I am currently creating a Game Center game, and am using the peer-to-peer functionality available. However, I would like to select one of the players (2 players) to act as a host, to ensure synchronization.

What is the best way to select a host (even randomly) from the players available and ensure that the other device knows which host was chosen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

知你几分 2024-12-18 09:27:59

这个 是一个很好、简单的教程,其中的代码演示了如何执行此操作。他们随机选择一位同伴作为主持人。希望有帮助!

This is a nice, simple tutorial with code that demonstrates how to do this. They randomly choose one of the peers to be the host. Hope that Helps!

没有你我更好 2024-12-18 09:27:59

执行该操作的示例代码

NSString *uid = [[UIDevice currentDevice] uniqueIdentifier];
CoinTossID = [uid hash];

已经发布了答案,这里仍然是现在在委托函数中

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID
    {
        NSMutableArray *ReceivedArray = [[NSMutableArray alloc] init];
        ReceivedArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        int flag = [[ReceivedArray objectAtIndex:0] intValue];
        [ReceivedArray removeObjectAtIndex:0];

        int CoinValue = [ReceivedCoinTossID intValue];
        if(CoinValue > CoinTossID)
        {
           isPlayer1 = YES;
        }
        else
        {
              isPlayer1 = NO;
        }
    }

already posted answer , still here is sample code to do that thing

NSString *uid = [[UIDevice currentDevice] uniqueIdentifier];
CoinTossID = [uid hash];

now in delegate Function

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID
    {
        NSMutableArray *ReceivedArray = [[NSMutableArray alloc] init];
        ReceivedArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        int flag = [[ReceivedArray objectAtIndex:0] intValue];
        [ReceivedArray removeObjectAtIndex:0];

        int CoinValue = [ReceivedCoinTossID intValue];
        if(CoinValue > CoinTossID)
        {
           isPlayer1 = YES;
        }
        else
        {
              isPlayer1 = NO;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文