Adding Game Center Leaderboard

旧城冷巷雨未停 提交于 2019-12-12 02:15:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!