0
我目前正在使用Swift開發我的第一款iOS遊戲。不幸的是,到目前爲止,我在實現Gamecenter方面遇到了更多問題。Gamecenter排行榜使用SpriteKit無法使用Swift完成按鈕
搞清楚如何讓領先彈出,並保存在我的下一個問題榜我撞到後:
我怎樣才能讓「完成」按鈕上的工作?如果我按它沒有任何反應。
首先我所有代碼:
GameViewController.swift:
import GameKit
....
override func viewWillLayoutSubviews() {
let skView = self.view as SKView
skView.ignoresSiblingOrder = true
let scene = GameScene.sceneWithSize(skView.bounds.size)
scene.scaleMode = .AspectFill
skView.presentScene(scene)
authenticateLocalPlayer()
}
func authenticateLocalPlayer(){
var localPlayer = GKLocalPlayer()
println(localPlayer)
localPlayer.authenticateHandler = {(viewController, error) -> Void in
if ((viewController) != nil) {
self.presentViewController(viewController, animated: true, completion: nil)
}else{
println((GKLocalPlayer.localPlayer().authenticated))
}
}
}
GameScene.swift:
import GameKit
....
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
var touch:UITouch = touches.anyObject() as UITouch
var location:CGPoint = touch.locationInNode(self)
if gameCenterRect.contains(location) {
var vc = self.view?.window?.rootViewController
var gc = GKGameCenterViewController()
vc?.presentViewController(gc, animated: true, completion: nil)
}
func saveHighscore(score:Int){
NSUserDefaults.standardUserDefaults().setObject(score, forKey: "kHighscore")
if GKLocalPlayer.localPlayer().authenticated {
var scoreReporter = GKScore(leaderboardIdentifier: "LEADERBOARD_ID")
scoreReporter.value = Int64(self.highscore)
var scoreArray: [GKScore] = [scoreReporter]
//println("report score \(scoreReporter)")
GKScore.reportScores(scoreArray, {(error : NSError!) -> Void in
if error != nil {
println("error")
//NSLog(error.localizedDescription)
}
})
}
}
我在哪裏有東西添加到我的代碼來獲得背部?