Opening Game Center in our game
If the user is authenticated, we will add a button to the MenuScene
class so 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
MenuScene.swift
in 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
MenuScene
class so that our class adopts theGKGameCenterControllerDelegate
protocol. This allows the Game Center screen to inform our scene when the player closes the Game Center:class MenuScene: SKScene, GKGameCenterControllerDelegate ...
Get Swift 3 Game Development - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.