我一直试图在SKScene上展示一个游戏中心排行榜一段时间了,我无法弄清楚我已经看过多篇文章..来自谷歌和这里当我点击带来的按钮你到这个场景它带你到那里并显示一个灰色屏幕,这就是我已经验证了播放器和一切。视图是否可能在场景后面? 这是我正在使用的场景
#import "DMLeaderBoard.h"
#import "DMGameKitHelper.h"
@implementation DMLeaderBoard
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
[self showLeaderboard];
}
return self;
}
-(void)showLeaderboard {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
if (leaderboardController != NULL)
{
leaderboardController.leaderboardIdentifier = @"1";
leaderboardController.viewState = GKGameCenterViewControllerStateLeaderboards;
leaderboardController.gameCenterDelegate = self;
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: leaderboardController animated: YES completion:nil];
}
}
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)viewController
{
UIViewController *vc = self.view.window.rootViewController;
[vc dismissViewControllerAnimated:YES completion:nil];
}
@end
答案 0 :(得分:1)
在showLeaderboard
中运行didMoveToView
方法,因为在初始化期间self.view
为nil
。