swift – 如何实现GameCenter排行榜?

前端之家收集整理的这篇文章主要介绍了swift – 如何实现GameCenter排行榜?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法在Stack Overflow上关注其他教程和答案,那么如何在我的游戏中实现GameCenter Leaderboards,在 Swift的SpriteKit中呢?一个人会使用什么代码,它会进入GameScene或GameViewController吗?我已经在iTunes Connect上设置了排行榜.我该怎么做?谢谢!

解决方法

首先,您必须验证播放器:

var localPlayer = GKLocalPlayer.localPlayer()
    localPlayer.authenticateHandler = {(viewController : UIViewController!,error : NSError!) -> Void in
        if ((viewController) != nil) {
            self.presentViewController(viewController,animated: true,completion: nil)
        }else{

            println((GKLocalPlayer.localPlayer().authenticated))
        }
    }

然后你可以打开排行榜

func showLeaderboard() {


        var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
        gcViewController.gameCenterDelegate = self

        gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards


        gcViewController.leaderboardIdentifier = "YOUR_BOARD_NAME"

        self.showViewController(gcViewController,sender: self)
        self.navigationController?.pushViewController(gcViewController,animated: true)

    }
    func gameCenterViewControllerDidFinish(gcViewController: GKGameCenterViewController!)
    {

        self.dismissViewControllerAnimated(true,completion: nil)
    }

我建议你在视图控制器中做这些.在viewDidAppear上验证播放器,但不是viewDidLoad

原文链接:/swift/819033.html

猜你在找的Swift相关文章