我正在制作一个带有精灵套件的游戏,在我使用GameCenter
之前一切正常,这是我的代码
define the Gameviewcontroller:
var GameController:GameViewController = GameViewController()
当您触摸TouchecBegan
:
let touchLocation = (touches as NSSet).anyObject()?.locationInNode(self)
let targetNode = self.nodeAtPoint(touchLocation!)
if targetNode.name == "leader"{
print("hhhh")
GameController.showGamecenetr()
}
在GameViewController
代码ShowGameCenter
内:
func showGamecenetr() {
print("jijijijji")
GameKitHelper.sharedInstance.showGKGameCenterViewController(self)
}
它应弹出GameCenter
的视图,但它显示错误:
无法将UIView
类型的值转换为SubView
我发现这是一个非常简单的错误,但我之前从未见过它,我不知道如何处理它,有人可以帮助我吗?
以下是showGKGameCenterViewController()
func showGKGameCenterViewController(viewController:UIViewController!){
if !gamecenterEnable {
print("No user!")
return
}
let gameCenterViewController = GKGameCenterViewController()
gameCenterViewController.gameCenterDelegate = self
gameCenterViewController.viewState = .Leaderboards
viewController.presentViewController(gameCenterViewController, animated: true, completion: nil)
}
帮助帮助;(
答案 0 :(得分:1)
所以我假设您验证了本地播放器/用户。
要打开=IF(L2=1,IF(OR(L1=0,ISTEXT(L1)),B2,M1),"")
,只需在场景中执行此操作
GameCenter
你场景中的 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
let touchedNode = nodeAtPoint(location)
if targetNode.name == "leader"{
let gcViewController: GKGameCenterViewController = GKGameCenterViewController()
gcViewController.gameCenterDelegate = self
gcViewController.leaderboardIdentifier = kLeaderboardID
gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
let vc: UIViewController = self.view!.window!.rootViewController!
vc.presentViewController(gcViewController, animated: true, completion: nil)
}
}
}
GKGameCenterControlleDelegate
和
class GameScene: SKScene, GKGameCenterControllerDelegate {