在Sprite Kit中解散游戏中心

时间:2014-03-29 15:44:49

标签: ios sprite-kit game-center

这就是我在MyScene.m中的内容

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
SKLabelNode *touchedNode = (SKLabelNode *)[self nodeAtPoint:positionInScene];
if ([[touchedNode name] isEqualToString:@"Leaderboard"])
{
    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController    alloc] init];
    if (leaderboardController != NULL)
    {
        leaderboardController.category = self.currentLeaderBoard;
        leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardController.leaderboardDelegate = self;
        GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
        if (gameCenterController != nil)
        {
            gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
            UIViewController *vc = self.view.window.rootViewController;
            [vc presentViewController: gameCenterController animated: YES completion:nil];
        }

    }
}
}

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController*)gameCenterViewController 
{
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}

我已将精灵设置为排行榜按钮,它会打开排行榜,但我无法关闭它。 代码没有给我任何错误。我该怎么办?

1 个答案:

答案 0 :(得分:0)

这对我有用:

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{ [gameCenterViewController.presentingViewController dismissViewControllerAnimated:YES completion:^(void){}]; }