简体   繁体   English

iOS Game Center 提交 float 而不是 int64_t

[英]iOS Game Center submit float instead of int64_t

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 .我正在尝试向我的 Game Center 排行榜提交两位小数长度的float ,但是允许提交的唯一格式是int64_t I am using the default Apple report score method:我正在使用默认的 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];
    }];
}

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.请帮忙,我一直在疯狂搜索,找不到答案。

GameCenter only accepts int64_t GameCenter 只接受 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.显示为浮点数或十进制值的值与显示为整数的值之间的唯一区别是小数点的 position,而实际上它们都是 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.如果您的内部表示是双精度的,并且您将游戏中心配置为在小数点后显示 3 位数字,则必须通过乘以 10^3 并转换为 integer 将其转换为 integer。

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

You can only submit 64 bit integers as scores to a leaderboard.您只能将 64 位整数作为分数提交到排行榜。 From the documentation :文档中:

To Game Center, a score is just a 64-bit integer value reported by your application.对于 Game Center,分数只是您的应用程序报告的 64 位 integer 值。 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.当您准备好将排行榜添加到您的应用程序时,您可以在 iTunes Connect 上配置排行榜,以告诉 Game Center 应如何格式化得分并将其显示给玩家。 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.在 iTunes Connect 中配置排行榜的一个关键优势是 Game Center 应用程序可以显示您的游戏得分,而无需您编写任何代码。

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.听起来为了显示类似浮动的乐谱,您必须修改 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);
}

You can see the GKScore.h file.您可以看到 GKScore.h 文件。

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

So float value now is not available.所以浮点值现在不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM