使用Sprite Kit实现Game Center

时间:2015-01-21 12:45:15

标签: objective-c sprite-kit game-center game-center-leaderboard

我无法在我的SpriteKit游戏中实施Game Center。

我屏幕上的大部分教程都需要ViewDidLoad我的游戏没有。 我无法找到正确的代码来验证我的游戏,或者可能是我有正确的代码,但我把它放在我的应用程序的错误区域。

目前我已将身份验证放在initWithSize中:

#import <GameKit/GameKit.h>
@interface GameScene ()
...
@implementation GameScene
...

-(id)initWithSize:(CGSize)size { /* Setup your scene here */
    if (self = [super initWithSize:size]) {
        self.anchorPoint = CGPointMake(0.5,0.5);
        self.physicsWorld.contactDelegate = self;
        ...
        ...
**(I HAVE BEEN PLACING AUTHENTICATE CODE FOUND ON INTERNET HERE, BUT NOTHING FOUND TO BE WORKING)**
    }
    return self;
}

下面的代码是我有一个名为&#34; Leaderboards&#34;的UILabel节点的地方。我希望我的播放器能够点击,并允许用户登录游戏中心并查看排行榜以及他自己的分数。

(当前点击时,它显示&#34;游戏中心不可用,玩家未登录&#34;,然后点击确定后,用户无法返回游戏,但游戏屏幕被冻结?)

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];

//if fire button touched, bring the rain


if ([node.name isEqualToString:@"LBButtonNode"]) {
    NSLog(@"leader boards opened");

    GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController    alloc] init];
    if (leaderboardController != NULL)
    {
        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];
        }  
    }
}
else if(!self.isStarted) {
    [self start];
}
else if (self.isGameOver) {
    [self clear];
}
else if (self.isStarted) {
    [hero jump];
}

}

如何使用SpriteKit正确实现Game Center功能?

0 个答案:

没有答案