O'Reilly logo

Swift 3 Game Development - Second Edition by Stephen Haney

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Open MenuScene.swift in Xcode.
  2. Add a new import statement at the top of the file so we can use the GameKit framework:
            import GameKit 
    
  3. Update the line that declares the MenuScene class so that our class adopts the GKGameCenterControllerDelegate protocol. This allows the Game Center screen to inform our scene when the player closes the Game Center:
            class MenuScene: SKScene, GKGameCenterControllerDelegate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required