我对Swift很陌生,而且我在游戏中实现排行榜时遇到了一些麻烦.我刚看了一个教程:'游戏中心排行榜!(Xcode中的Swift 2)'其中GameCenter信息都通过应用程序的一个视图.在我的游戏中,我希望用户能够玩游戏,然后只有当他们处于特定SKScene意愿时他们才能访问GameCenter.
因此,例如,在GameOverScene意志上他们将被用户认证,并且还能够上传他们的高分.我想我也错过了GameViewController(所有教程逻辑所在的位置)和我制作的众多场景之间的一些差异.
这是我的代码,我尝试使用GKGameCenterControllerDelegateon GameOverScene和创建各种函数来访问GameCenter.当用户在视图中点击某个标签时进行调用:(这显然不起作用,因为我试图访问这样的行上的场景:self.presentViewController(view!, animated:true, completion: nil)
class GameOverScene: SKScene, GKGameCenterControllerDelegate {
init(size: CGSize, theScore:Int) {
score = theScore
super.init(size: size)
}
...
override func didMoveToView(view: SKView) {
authPlayer()
leaderboardLabel.text = "Tap for Leaderboard"
leaderboardLabel.fontSize = 12
leaderboardLabel.fontColor = SKColor.redColor()
leaderboardLabel.position = CGPoint(x: size.width*0.85, y: size.height*0.1)
addChild(leaderboardLabel)
...
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch : AnyObject in touches {
let location = touch.locationInNode(self)
if(CGRectContainsPoint(leaderBoardLabel.frame, location)){ …Run Code Online (Sandbox Code Playgroud)