在spritekit我不能弹出GameCenter视图

时间:2015-11-26 14:04:38

标签: ios swift sprite-kit game-center game-center-leaderboard

我正在制作一个带有精灵套件的游戏,在我使用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)

    }

帮助帮助;(

1 个答案:

答案 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 {