GameKit发送不同的分数类型

时间:2012-10-26 16:01:15

标签: objective-c ios game-center gamekit

我的应用程序有5种不同的游戏模式,其中3种具有整数分数,其中2种具有基于时间的分数(他们完成游戏的速度有多快)。

如何设置我的reportScore:方法,以便我在iTunes Connect中设置的排行榜(以最低到最高时间格式显示高分百分之一< / em> of a second)将以时间格式收到我的用户分数?

我想将其作为NSTimeInterval发送。

Apple Docs指定的方法仅接受整数作为分数:

- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];
    scoreReporter.value = score;

    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil)
        {
            //handle the score to submit again later
        }
    }];
}

更新

我已经对此做了一些研究,我知道你只能将分数作为int64_t发送到Game Center排行榜。那么如何格式化这个整数,以便我的排行榜将其格式化为百分之一秒?

感谢您的帮助!

1 个答案:

答案 0 :(得分:5)

来自Apple's documentation

  

分数对象提供的值仅在格式化显示时由Game Center解释。您可以确定在iTunes Connect上定义排行榜时如何格式化分数。

即,您需要将时间转换为整数并发送。如果你想要1 / 100s精度,你可以将浮点NSTimeInterval乘以100并将其舍入为整数(例如,1.567s - > 157),然后发送并相应地选择排行榜格式(“Elapsed”时间 - 到百分之一秒“,如果我没记错的话。”