September 2018
Intermediate to advanced
434 pages
8h 47m
English
It is simple to send a new score to the leaderboard from the code. Follow these steps to send the number of coins collected to the leaderboard every time a game ends:
GameSCNScene.swift.import GameKit
GameSCNScene class named updateLeaderboard, as shown here: func updateLeaderboard() { if GKLocalPlayer.localPlayer().isAuthenticated { // Create a new score object, with our leaderboard: let highScore = GKScore(leaderboardIdentifier: "highscore") // Set the score value to our coin score: highScore.value = Int64(self.score) // Report the score (wrap the score in an array) GKScore.report([highScore], ...Read now
Unlock full access