iOS 游戏中心提交 float 而不是 int64_t
我正在尝试向我的游戏中心排行榜提交两位小数长度的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GameCenter 只接受 int64_t
浮点数或小数形式的值与整数形式的唯一区别在于小数点的位置,而实际上它们都是 int64_t。
如果您的内部表示形式是双精度型,并且您将游戏中心配置为在小数点后显示 3 位数字,则必须通过乘以 10^3 并将其转换为整数来将其转换为整数。
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.
您只能将 64 位整数作为分数提交到排行榜。来自文档:
该文档页面应该告诉您有关格式化乐谱的信息。听起来为了显示类似浮动的乐谱,您必须修改 iTunes Connect 中的格式设置。
更新
试试这个来增加分数:
You can only submit 64 bit integers as scores to a leaderboard. From the documentation:
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:
您可以看到 GKScore.h 文件。
所以浮点值现在不可用。
You can see the GKScore.h file.
So float value now is not available.