Search code examples
iosiphoneswiftxcode6game-center-leaderboard

Game Center in Swift Sprite Kit


I am trying to add Game Center Leaderboards and achievements into my game but I can not find any tutorials for SpriteKit in Swift. All of the tutorials have

    self.presentViewController(viewController, animated: true, completion: nil)

but in Sprite Kit that doesn't work


Solution

  • You can just call it like that, if you are in a UIViewController already. But if you want to show an UIViewController from your SKScene you should access the rootViewController and present the controller from there:

    self.view?.window?.rootViewController?.presentViewController(yourViewController, animated: true, completion: nil)