iOS 游戏中心提交 float 而不是 int64_t

发布于 2024-11-19 05:16:33 字数 778 浏览 3 评论 0原文

我正在尝试向我的游戏中心排行榜提交两位小数长度的float,但是允许提交的唯一格式是int64_t。我正在使用默认的Apple报告评分方法:

- (void)reportScore:(int64_t)score forCategory:(NSString *)category {
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];   
    scoreReporter.value = score;
    [scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) {
        [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
    }];
}

我正在尝试使用此方法向报告评分方法提供分数:

- (IBAction)increaseScore {
    self.currentScore = self.currentScore + 1;
    currentScoreLabel.text = [NSString stringWithFormat: @"%lld", self.currentScore];
    NSLog(@"%lld", self.currentScore);
}

请帮忙,我一直在疯狂地谷歌搜索,但找不到答案。

I am trying to submit a float of two decimal length to my Game Center leaderboard, however the only format allowed to submit with is int64_t. I am using the default Apple report score method:

- (void)reportScore:(int64_t)score forCategory:(NSString *)category {
    GKScore *scoreReporter = [[GKScore alloc] initWithCategory:category];   
    scoreReporter.value = score;
    [scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) {
        [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
    }];
}

I am trying to use this method to provide the score to the report score method:

- (IBAction)increaseScore {
    self.currentScore = self.currentScore + 1;
    currentScoreLabel.text = [NSString stringWithFormat: @"%lld", self.currentScore];
    NSLog(@"%lld", self.currentScore);
}

Please help, I have been googling like crazy and cannot find the answer to this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南烟雨〆相思醉 2024-11-26 05:16:33

GameCenter 只接受 int64_t

浮点数或小数形式的值与整数形式的唯一区别在于小数点的位置,而实际上它们都是 int64_t。

如果您的内部表示形式是双精度型,并且您将游戏中心配置为在小数点后显示 3 位数字,则必须通过乘以 10^3 并将其转换为整数来将其转换为整数。

int64_t gameCenterScore = (int64_t)(doubleValue * 1000.0f)

GameCenter only accepts int64_t

The only difference between values that appear like floats or decimal values and those that appear as integers is the position of the decimal mark, while in fact all of them are int64_t.

If your internal representation is a double and you configured game center to show 3 digits after the decimal mark you have to convert it to an integer by multiplying with 10^3 and casting to integer.

int64_t gameCenterScore = (int64_t)(doubleValue * 1000.0f)
云醉月微眠 2024-11-26 05:16:33

您只能将 64 位整数作为分数提交到排行榜。来自文档

对于 Game Center 来说,分数只是一个
您报告的 64 位整数值
应用。您可以自由决定
分数意味着什么,以及你如何
应用程序计算它。当你
准备好将排行榜添加到
您的应用程序,您配置
iTunes Connect 上的排行榜告诉你
Game Center 的分数应该是多少
格式化并显示给播放器。
此外,您还提供本地化字符串
这样就可以显示分数
正确地使用不同的语言。一个
配置的主要优点
iTunes Connect 中的排行榜是
游戏中心应用程序可以显示
没有你的情况下你的游戏得分
编写任何代码。

该文档页面应该告诉您有关格式化乐谱的信息。听起来为了显示类似浮动的乐谱,您必须修改 iTunes Connect 中的格式设置。

更新

试试这个来增加分数:

- (IBAction) increaseScore {      
     self.currentScore = self.currentScore + 5; 
     float score = (float)self.currentScore / 100.0f;
     currentScoreLabel.text = [NSString stringWithFormat: @"%f", score]; 
     NSLog(@"%lld", self.currentScore);
}

You can only submit 64 bit integers as scores to a leaderboard. From the documentation:

To Game Center, a score is just a
64-bit integer value reported by your
application. You are free to decide
what a score means, and how your
application calculates it. When you
are ready to add the leaderboard to
your application, you configure
leaderboards on iTunes Connect to tell
Game Center how a score should be
formatted and displayed to the player.
Further, you provide localized strings
so that the scores can be displayed
correctly in different languages. A
key advantage of configuring
leaderboards in iTunes Connect is that
the Game Center application can show
your game’s scores without you having
to write any code.

That doc page should tell you about formatting your score. It sounds like in order to display float-like scores you will have to tinker with the format settings in iTunes Connect.

Update

Try this for increaseScore:

- (IBAction) increaseScore {      
     self.currentScore = self.currentScore + 5; 
     float score = (float)self.currentScore / 100.0f;
     currentScoreLabel.text = [NSString stringWithFormat: @"%f", score]; 
     NSLog(@"%lld", self.currentScore);
}
郁金香雨 2024-11-26 05:16:33

您可以看到 GKScore.h 文件。

@property(nonatomic, assign)            int64_t     value;              // The score value as a 64bit integer.

所以浮点值现在不可用。

You can see the GKScore.h file.

@property(nonatomic, assign)            int64_t     value;              // The score value as a 64bit integer.

So float value now is not available.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文