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.