问题描述
我一直试图在我的Sprite Kit游戏中实现Game Center,但是每次我尝试展示排行榜...
I've been trying to implement Game Center in my Sprite Kit game, but every time I try to present the leaderboard...
-(void)showLeaderboard:(UIViewController*)gcvc {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
if (leaderboardController != NULL)
{
leaderboardController.leaderboardIdentifier = @"Game_Leaderboard";
leaderboardController.viewState = GKGameCenterViewControllerStateLeaderboards;
leaderboardController.gameCenterDelegate = self;
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: leaderboardController animated: YES completion:nil];
}
}
游戏在启动时因错误而崩溃:
The game crashes on startup with the error:
我已经查找了相关的问题,所有这些问题都建议将IB中的View类更改为SKView类,但是没有运气.异常断点在以下行停止:
I've looked up related questions and all of them suggest changing the View's class in IB to SKView class, but no luck. The exception breakpoint stops at the line:
SKView *spriteView = (SKView *)self.view;
spriteView.showsDrawCount = YES;
该视图显然是SKView类型的,但是它仍然说spriteView是UIView类型的.我不确定这是否重要,因为游戏的主视图控制器是UIViewController的子类,而这是呈现Game Center排行榜所需要的,因此我不知道如何解决此错误.
And the view is clearly of type SKView, but it still says that spriteView is of type UIView.I'm not sure if it should even matter since the game's main view controller is a subclass of UIViewController, which is what is needed to present the Game Center Leaderboard so I have no idea how to fix this error.
推荐答案
通常,我通常从主UIViewController中获取SKView,如下所示:
For what it's worth, I usually obtain the SKView from the main UIViewController like so:
/// Returns the Director's own view, but as a SKView *.
@property (weak, readonly) SKView * skview;
// ...
- (SKView *) skview {
return (SKView *)self.view;
}
这篇关于UIView不会转换为SKView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!