Opening Game Center in our game
If the user is authenticated, we will add a button to the MenuScene class so that they can open the leaderboard and view achievements from within our game. Alternatively, players can always use the Game Center app in iOS to view their progress.
Follow these steps to create a leaderboard button in the menu scene:
- Open
OverlaySKScene.swiftin Xcode. - Add a new import statement at the top of the file so we can use the GameKit framework:
import GameKit
- Update the line that declares the
OverlaySKSceneclass so that our class adopts theGKGameCenterControllerDelegateprotocol. This allows the Game Center screen to inform our scene when the player closes the Game Center:class OverlaySKScene: SKScene, SKPaymentTransactionObserver, SKProductsRequestDelegate, GKGameCenterControllerDelegate {Add two
nwvariables at the top of theOverlauSKSceneto add the leaderboard text and to check if the player was authenticated:var leaderboardText: SKLabelNode!...