5

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

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

我想把它作为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
        }
    }];
}

更新

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

谢谢你的帮助!

4

1 回答 1

5

来自苹果的文档

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

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

于 2012-10-26T16:09:57.277 回答