游戏中心与Sprite Kit集成?
如何将Game Center或GameKit Framework与Sprite Kit Xcode模板一起使用? 在Sprite工具包中,它使用场景;但通常要查看排行榜,例如您需要“presentModalViewController”,但这在SKView中是不可能的。游戏中心与Sprite Kit集成?
我怎样才能提前
感谢验证玩家和所有其他有趣的东西在的iOS 6
!
你可以这样
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil)
{
static_setEnable(true);
NSLog(@" Authenticate local player complete");
}
else
{
static_setEnable(false);
NSLog(@"Authenticate local player Error: %@", [error description]);
}
}];
}
这不是一个很好的答案,因为SpriteKit仅适用于iOS 7,但自iOS 6以来不推荐使用'authenticateWithCompletionHandler:'。 – idmean
验证您可以通过使用此代码访问根视图控制器
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: gameCenterController animated: YES completion:nil];
现在,您可以访问您的ModelViewController任何地方包括SKScenes使用“presentModalViewController”。我在最新的游戏中做到了,并且效果不错
另外,我建议你使用单独的对象来控制游戏中心,比如排行榜和成就,这样你就可以在你的下一个游戏中重用它。
其不适用工作,所以我试着这... GKGameCenterViewController * vc = [[GKGameCenterViewController alloc] init]; [vc presentViewController:vc animated:YES completion:nil];和stil不工作 – iDevMartin
我会继续努力,并让你张贴,谢谢反正! – iDevMartin
这里是一个更新的身份验证本地球员,但拉文德拉的代码也可以。
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil)
{
//showAuthenticationDialogWhenReasonable: is an example method name. Create your own method that displays an authentication view when appropriate for your app.
//[self showAuthenticationDialogWhenReasonable: viewController];
}
else if (localPlayer.isAuthenticated)
{
//authenticatedPlayer: is an example method name. Create your own method that is called after the loacal player is authenticated.
//[self authenticatedPlayer: localPlayer];
}
else
{
//[self disableGameCenter];
}
};
}
雨燕2.0
func authenticateLocalPlayer() {
let localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = { (viewController, error) -> Void in
if (viewController != nil) {
let vc:UIViewController = self.view!.window!.rootViewController!
vc.presentViewController(viewController!, animated: true, completion:nil)
} else {
print ("Authentication is \(GKLocalPlayer.localPlayer().authenticated) ")
GlobalData.loggedIntoGC = true
// do something based on the player being logged in.
全球国际斯威夫特文件:在您的场景
static var loggedIntoGC:Bool = false
呼叫方法,其中被启用游戏中心: 即HUD或GameScene在
override func didMoveToView(view: SKView)`
authenticateLocalPlayer()
你可以使用modalViews - 我将它用于我的设置,效果很好。这会让你开始,UIViewController * vc = self.view.window.rootViewController – DogCoffee
谢谢,我会试试看! – iDevMartin
如果你不能得到它的工作,发布另一个问题,并为你写病答案。 – DogCoffee