Also versuche ich Spiel-Center zu meinem Spiel hinzufügen, aber da, dass es in spriteKit es nicht funktionieren wird ..Integrieren Game Center - werfen Wert vom Typ ‚UIView‘ zu SKView“Fehler
i gesucht haben und auf der Suche und evrything weist darauf hin, dass es nur möglich in einem UIViewController ist ..
all meine Knöpfe kaufen (wie die Taste, um Highscore zu gehen (Rangliste) ist in spriteKit ...
so jetzt habe ich die Fehler
Could not cast value of type 'UIView' (0x3755c3d8) to 'SKView' (0x36e116cc).
Das ist mein GameViewController (Die einzige Datei mit einem UIViewController), aber es wird verwendet, um zu zeigen, mir nur die TitleScene
class GameViewController: UIViewController, GKGameCenterControllerDelegate {
var gameCenterViewController = GKGameCenterViewController()
var scene : TitleScene?
var gcEnabled = Bool()
var gcDefaultLeaderBoard = String()
func authenticateLocalPlayer() {
let localPlayer: GKLocalPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(GameViewController, error) -> Void in
if((GameViewController) != nil) {
// 1 Show login if player is not logged in
self.presentViewController(GameViewController!, animated: true, completion: nil)
} else if (localPlayer.authenticated) {
// 2 Player is already euthenticated & logged in, load game center
self.gcEnabled = true
// Get the default leaderboard ID
localPlayer.loadDefaultLeaderboardIdentifierWithCompletionHandler({ (leaderboardIdentifer: String?, error: NSError?) -> Void in
if error != nil {
print(error)
} else {
self.gcDefaultLeaderBoard = leaderboardIdentifer!
}
})
} else {
// 3 Game center is not enabled on the users device
self.gcEnabled = false
print("Local player could not be authenticated, disabling game center")
print(error)
}
}
}
func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController) {
gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
let skView = self.view as! SKView
self.authenticateLocalPlayer()
scene = TitleScene(size: skView.bounds.size)
// Configure the view.
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene!.scaleMode = SKSceneScaleMode.AspectFit
scene!.size = self.view.bounds.size
skView.presentScene(scene)
}
und in meinem TitleScene bekam ich den
class TitleScene: SKScene {
if highScoreBtn.containsPoint(location) {
let ScoreleaderboardID = "ScoreLeaderboardID"
let sScore = GKScore(leaderboardIdentifier: ScoreleaderboardID)
sScore.value = Int64(score)
let localPlayer: GKLocalPlayer = GKLocalPlayer.localPlayer()
let gcVC: GKGameCenterViewController = GKGameCenterViewController()
gcVC.gameCenterDelegate = GameViewController()
gcVC.viewState = GKGameCenterViewControllerState.Leaderboards
gcVC.leaderboardIdentifier = "LeaderboardID"
self.view?.window?.rootViewController?.presentViewController(GameViewController(), animated: true, completion: nil)
GKScore.reportScores([sScore], withCompletionHandler: { (error: NSError?) -> Void in
if error != nil {
print(error!.localizedDescription)
} else {
print("Score submitted")
}
})
print("highScoreBtn")
}