iPhone GameCenter 邀请玩家组

发布于 2024-10-28 03:54:12 字数 483 浏览 2 评论 0原文

我开发了一个使用 GameCenter 的 iPhone 应用程序。为了支持不同级别的游戏,我在 GKMatchRequest 类中设置了playerGroup。如果比赛是通过自动匹配过程开始的,则两个用户都知道playerGroup,但如果使用邀请过程,则被邀请者不知道playerGroup。

[viewController matchRequest].playerGroup读取方法中的playerGroup

-   (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match

我尝试使用

,但属性playerGroup始终返回0,而不是正确的玩家组。

有谁知道如何解决这个问题。我需要知道玩家组才能加载正确的关卡。

非常感谢您的帮助

I developed an iPhone App that uses the GameCenter. To support different levels of my game I set the playerGroup within the GKMatchRequest class. If the match is started by an automatic match making process both users knows the playerGroup, but if the invitation process is used, the invitee does not know the playerGroup.

I tried to read the playerGroup within the method

-   (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match

by using

[viewController matchRequest].playerGroup, but the property playerGroup always return 0, instead the right player group.

Does anyone have an idea how to solve this problem. I need to know the playerGroup to load the right level.

Thank you very much for your help

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

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

发布评论

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

评论(3

懷念過去 2024-11-04 03:54:12

据我所知,这是 Game Center 的内置限制。我也一直在苦苦挣扎,并在几个论坛上询问,包括苹果开发论坛,但没有任何回应。我已经向 Apple 写了一份错误报告,我建议您也这样做。

作为我自己的游戏中的一种解决方法,我有几个不同的规则集供玩家选择,并且玩家必须共享相同的规则才能进行多人比赛,因此我在游戏实际开始后进行了“双重检查”,以确保每个人遵循相同的规则:以防万一有人被邀请并使用了错误的规则。

我所做的是,一旦游戏开始(您应该在 GKMatchMakerViewControllerDelegatedidFindMatch 方法和 match:player:didChangeState 中检测到: GKMatchDelegate中)我让玩家进入游戏,然后将包含他们使用的规则的包发送给所有其他玩家。当他们收到这些数据时,他们会将其与自己的规则进行匹配,如果有人使用了错误的规则,游戏将发出警报并中断比赛。

这有点难看,很明显,Apple 应该实现一种在通过邀请初始化时为 GKMatchMakerViewController 设置 GKMatchRequest 的方法。但至少它有效。

As far as I know, this is a built in limitation of Game Center. I have been struggling with it too, and asked on several forums, including Apples devforums, without any response. I've written a bug report to Apple and I suggest you do the same.

As a workaround in my own game, where I have several different rulesets that players choose from and where players have to share the same rules for multiplayer matches to work, I put in a "double check" after the game actually starts to make sure everyone is on the same rules: Just in case someone was invited and is using the wrong rules.

What I did is, as soon as the game starts (which you should detect for in both the didFindMatch method of the GKMatchMakerViewControllerDelegate and in match:player:didChangeState: in GKMatchDelegate) I let the players enter the game and then send out packages containing the rules they use to all the other players. When they receive this data, they match it with their own rules and if anyone is using the wrong rules, the game will put up an alert and disconnect the match.

It's a bit ugly, and it's very clear that Apple ought to implement a way to set a GKMatchRequest for a GKMatchMakerViewController when initialized by an invite. But at least it works.

梨涡少年 2024-11-04 03:54:12

我偶然发现了同样的问题。作为解决方法,我通过 GKMatch 对象发送包含所有相关游戏自定义信息的握手。我使用 GKMatchSendDataReliable DataMode 发送数据,因此握手不会失败。

客户端收集所有信息后,实际的游戏逻辑将在其基础上创建并启动。

I stumpled upon the same problem. As a workaround I am sending a handshake with all relevant game customization info through the GKMatch object. I send the data with GKMatchSendDataReliable DataMode so the handshake doesn't fail.

After all information is collected by the clients the actual game logic is created and started on its basis.

二智少女 2024-11-04 03:54:12

您可以像这样检查比赛请求的玩家组。

func player(player: GKPlayer, didAcceptInvite inviteToAccept: GKInvite)    {
    if inviteToAccept.playerGroup == 0 || inviteToAccept.playerGroup == myPlayerGroup  {
        inviteAccepted()
    }
    else {
        // TO SOMETHING
        myPlayerGroup = inviteToAccept.playerGroup
        inviteAccepted()
    }

You can check the Player Group of a match request like this.

func player(player: GKPlayer, didAcceptInvite inviteToAccept: GKInvite)    {
    if inviteToAccept.playerGroup == 0 || inviteToAccept.playerGroup == myPlayerGroup  {
        inviteAccepted()
    }
    else {
        // TO SOMETHING
        myPlayerGroup = inviteToAccept.playerGroup
        inviteAccepted()
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文