Tommy
Tommy

Reputation: 140

Adding Game Center Leaderboard

I am new to Swift and am having trouble adding a Game Center leaderboard into my Sprite Kit game. I created a button for the leaderboard but it is in an SKScene and it seems that the code for Game Center needs to be inside a View Controller? I have added the code into my single View Controller, but now I'm not sure where to go. Again, I am very new to this and completely lost -- any help would be greatly appreciated.

Upvotes: 1

Views: 156

Answers (1)

Johannes Knust
Johannes Knust

Reputation: 1021

you could create a cocoa touch class with the UIViewController Subclass. In the viewdidLoad you could use something like this:

if let view = self.view as! SKView? {
        // Load the SKScene from 'GameScene.sks'
        if let scene = SKScene(fileNamed: "Level1") {
            // Configure the scene
            [...]

            // Present the scene
            view.presentScene(scene)
        }

Don't forget to import GameKit.

Upvotes: 0

Related Questions