簡體   English   中英

迅速保存高分並在Game Center排行榜中顯示不同的排行榜

[英]Saving high scores and displaying different leaderboards in a Game Center leaderboard set with swift

我能夠顯示一個排行榜。 我在iTunes Connect中創建了一個排行榜集,但不確定如何將分數保存到排行榜集中的不同排行榜中。 我也不確定如何在Game Center的視圖控制器中顯示排行榜中的所有排行榜。

 func saveHighScore(highscore:Int){
            if GKLocalPlayer.localPlayer().authenticated {            
                let scoreReporter = GKScore(leaderboardIdentifier: "easymodehighscores")

                scoreReporter.value = Int64(highScore)

                let scoreArray : [GKScore] = [scoreReporter]

                GKScore.reportScores(scoreArray, withCompletionHandler: nil)

            }
        }

這是我將高分保存到排行榜之一的代碼。

    let viewController = self.view.window?.rootViewController
    let gameCenterVC = GKGameCenterViewController()
    gameCenterVC.gameCenterDelegate = self
    viewController?.presentViewController(gameCenterVC, animated: true, completion: nil)

這是我用於呈現Game Center視圖控制器的代碼。

我的解決方案是使用switch在不同的排行榜之間進行切換,僅使用排行榜標識符將高分保存到該排行榜中。 如果您在iTunes Connect中正確配置了所有內容,則游戲中心ViewController還將自動顯示此應用程序的所有排行榜。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM