问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/41691574/adding-game-center-leaderboard