添加游戏中心排行榜 [英] Adding Game Center Leaderboard
问题描述
我是Swift的新手,无法在我的Sprite Kit游戏中添加Game Center排行榜.我为排行榜创建了一个按钮,但它在SKScene中,似乎Game Center的代码需要在View Controller中?我已将代码添加到我的单个View Controller中,但是现在我不确定该去哪里.再说一次,我对此很陌生,完全迷失了,任何帮助将不胜感激.
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.
推荐答案
您可以使用UIViewController子类创建可可触摸类.在viewdidLoad中,您可以使用如下代码:
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)
}
别忘了导入GameKit.
Don't forget to import GameKit.
这篇关于添加游戏中心排行榜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!