我无法在我的 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;
}
下面的代码是我有一个UILabel
名为“Leaderboards”的节点,我希望我的玩家能够单击该节点,并允许用户登录游戏中心并查看排行榜以及他自己的分数。
(当前点击时提示“游戏中心不可用,玩家未登录”,然后点击确定后,用户无法返回游戏,游戏画面卡死?)
-(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 功能?