首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何迅速接受游戏中心的邀请

如何迅速接受游戏中心的邀请
EN

Stack Overflow用户
提问于 2014-11-21 18:40:19
回答 1查看 756关注 0票数 1

我有一些麻烦使邀请迅速接受。

有人能帮我做正确的编码吗?这是我的

代码语言:javascript
复制
GKMatchmaker.sharedMatchmaker().matchForInvite(Invitation!, completionHandler = {(InvitedMatch:GKMatch!, error: NSError!) -> Void in
        if InvitedMatch != nil {
            myMatch=match

            LocalGame=false

            if let scene = GameScene.unarchiveFromFile(environment_Prefix!+"GameScene") as? GameScene {
                // Configure the view.
                let skView = self.view as SKView!
                //skView.showsFPS = true
                //skView.showsNodeCount = true

                /* Sprite Kit applies additional optimizations to improve rendering performance */
                skView.ignoresSiblingOrder = true

                /* Set the scale mode to scale to fit the window */
                scene.scaleMode = .Fill

                skView.presentScene(scene, transition: SKTransition.flipVerticalWithDuration(2.0))

            }
        }
    })

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-22 11:42:54

最后,我想出了可行的解决方案。我必须像这样实现GKLocalPlayerListener,并在委托函数中调用invite匹配。

代码语言:javascript
复制
   func player(player: GKPlayer!, didAcceptInvite invite: GKInvite!) {

    GKMatchmaker.sharedMatchmaker().matchForInvite (invite, {(InvitedMatch, error) in

        if InvitedMatch != nil {
            myMatch=InvitedMatch

            LocalGame=false

            if let scene = GameScene.unarchiveFromFile(environment_Prefix!+"GameScene") as? GameScene {
                // Configure the view.
                let skView = self.view as SKView!
                //skView.showsFPS = true
                //skView.showsNodeCount = true

                /* Sprite Kit applies additional optimizations to improve rendering performance */
                skView.ignoresSiblingOrder = true

                /* Set the scale mode to scale to fit the window */
                scene.scaleMode = .Fill

                skView.presentScene(scene, transition: SKTransition.flipVerticalWithDuration(2.0))

            }
        }
    })
}

要获得调用的player函数,我必须在本地player认证块注册监听器,如下所示:

代码语言:javascript
复制
localPlayer.registerListener(self)

现在游戏邀请工作得很好。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27068111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档