如何在tvOS上显示GameCenter排行榜? [英] How to display GameCenter leaderboard on tvOS?

查看:176
本文介绍了如何在tvOS上显示GameCenter排行榜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

思考我遵循了所有必需的步骤来支持游戏中的排行榜(并且在iOS上也可以正常工作),但是在tvOS上,无法配置GKGameCenterViewController来显示排行榜特定的排行榜,LeaderboardIdentifier属性完全丢失(就像ViewState一样):

I think I followed all the required steps to support leaderboards in my game (and they work just fine on iOS), however on tvOS it is not possible to configure the GKGameCenterViewController to show a specific leaderboard, the LeaderboardIdentifier property is simply missing (just like the ViewState):

var leaderboardController = new GKGameCenterViewController ();

// Unavailable on tvOS
/*
leaderboardController.ViewState = GKGameCenterViewControllerState.Default;
leaderboardController.LeaderboardIdentifier = "myLeaderboardId";
*/ 

leaderboardController.Finished += (sender, e) =>
{
  leaderboardController.DismissViewController (true, null);
}

PresentViewController (leaderboardController, true, null);

我没有使用这些属性,而是按照此处的说明进行操作.我注意到,这将在最终的应用程序捆绑包中生成一个GKGameCenterContent.plist文件.我仔细检查了内容:

Instead of using these properties, I followed the instructions here. I notice that this will generate a GKGameCenterContent.plist file in the final app bundle. I double checked the content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>GKLeaderboards</key>
    <array>
        <dict>
            <key>identifier</key>
            <string>myLeaderboardId</string>
            <key>onDemandResourcesTag</key>
            <string>com.apple.gamecenter.Leaderboard</string>
            <key>posterImageName</key>
            <string>Leaderboard/Poster</string>
        </dict>
    </array>
</dict>
</plist>

这看起来绝对正确,图像当然也包含在包装中.不过,使用上面的代码显示游戏中心控制器只会给我成就屏幕,而没有其他显示.

This looks absolutely correct, also the images are of course in the bundle. Still, using the code above to show the game center controller will only give me the achievements screen and nothing else.

推荐答案

您必须将排行榜添加到Assets.xassets.您可以在其中输入标识符:

You have to add a leaderboard to Assets.xassets. There you can enter the identifier:

显示排行榜的代码:

@IBAction func openLeaderboard(sender: AnyObject) {

    let gcViewController = GKGameCenterViewController()
    gcViewController.gameCenterDelegate = self
    self.presentViewController(gcViewController, animated: true, completion: nil)
}

这篇关于如何在tvOS上显示GameCenter排行榜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆